Class FormFieldException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- google.registry.ui.forms.FormException
-
- google.registry.ui.forms.FormFieldException
-
- All Implemented Interfaces:
java.io.Serializable
@NotThreadSafe public final class FormFieldException extends FormException
Exception thrown when a form field contains a bad value.You can safely throw
FormFieldException
from within your validator functions, and the field name will automatically be propagated into the exception object for you.The way that field names work is a bit complicated, because we need to support complex nested field names like
foo[3].bar
. So what happens is the original exception will be thrown by aFormField
validator without the field set. Then as the exception bubbles up the stack, it'll be caught by theconvert
method, which then prepends the name of that component. Then when the exception reaches the user, thegetFieldName()
method will produce the fully-qualified field name.This propagation mechanism is also very important when writing
FormField.Builder.transform(java.lang.Class<T>, java.util.function.Function<O, T>)
functions, which oftentimes will not know the name of the field they're validating.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FormFieldException(FormField<?,?> field, java.lang.String userMessage)
Creates a newFormFieldException
for a particular form field.FormFieldException(java.lang.String userMessage)
Creates a newFormFieldException
FormFieldException(java.lang.String field, java.lang.String userMessage)
Creates a newFormFieldException
for a particular field name.FormFieldException(java.lang.String userMessage, java.lang.Throwable cause)
Creates a newFormFieldException
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
getFieldName()
Returns the fully-qualified name (JavaScript syntax) of the form field causing this error.int
hashCode()
FormFieldException
propagate(java.lang.String name)
Returns self withname
prepended, for propagating exceptions up the stack.java.lang.String
toString()
-
Methods inherited from class google.registry.ui.forms.FormException
getMessage
-
-
-
-
Constructor Detail
-
FormFieldException
public FormFieldException(@Detainted java.lang.String userMessage)
Creates a newFormFieldException
This exception should only be thrown from within a
FormField
converter function. The field name will automatically be propagated into the exception object for you.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.
-
FormFieldException
public FormFieldException(@Detainted java.lang.String userMessage, java.lang.Throwable cause)
Creates a newFormFieldException
This exception should only be thrown from within a
FormField
converter function. The field name will automatically be propagated into the exception object for you.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.cause
- the original cause of this exception (non-null).
-
FormFieldException
public FormFieldException(FormField<?,?> field, @Detainted java.lang.String userMessage)
Creates a newFormFieldException
for a particular form field.This exception should only be thrown from within a
FormField
MAP converter function in situations where you're performing additional manual validation.- Parameters:
userMessage
- should be a friendly message that's safe to show to the user.
-
FormFieldException
public FormFieldException(java.lang.String field, @Detainted java.lang.String userMessage)
Creates a newFormFieldException
for a particular field name.- Parameters:
field
- name corresponding to aFormField.name()
userMessage
- friendly message that's safe to show to the user
-
-
Method Detail
-
getFieldName
public java.lang.String getFieldName()
Returns the fully-qualified name (JavaScript syntax) of the form field causing this error.
-
propagate
@CheckReturnValue public FormFieldException propagate(java.lang.String name)
Returns self withname
prepended, for propagating exceptions up the stack.This would be package-private except that it needs to be called by a test class in another package.
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Throwable
-
-