Skip to content

Error messages

Each validation has one default message. The table below was produced by running every validation against a failing input with website/scripts/run.sh, so it matches the code. value is the field name placeholder: inside a schema it is the field key, after withName it is that name. A message or a message builder replaces the default.

ValidationCodeDefault message
l.string()invalidTypevalue must be a string
l.int()invalidTypevalue must be an integer
l.double()invalidTypevalue must be a double
l.num()invalidTypevalue must be a number
l.bool()invalidTypevalue must be a bool
l.list(...)invalidTypevalue must be a list
l.map()invalidTypevalue must be a map
l.schema({...})invalidTypevalue must be a map
l.file()invalidTypevalue must be a file
l.nullValue()invalidTypevalue must be null
l.union([...])invalidUnionvalue does not match any allowed option
l.oneOf(['a', 'b'])notOneOfvalue must be one of: a, b
.required()requiredvalue is required
.custom(f)customvalue does not pass custom validation
.customWithSchema(f)customvalue does not pass schema custom validation
.min(8) on a stringtooShortvalue must be at least 8 characters long
.max(3) on a stringtooLongvalue must not be more than 3 characters long
.length(3)invalidLengthvalue must be exactly 3 characters long
.contains('@')missingSubstringvalue does not contain "@"
.startsWith('+')missingPrefixvalue does not start with "+"
.endsWith('.dart')missingSuffixvalue does not end with ".dart"
.regex(RegExp(r'^\d+$'))invalidPatternvalue must match the pattern ^\d+$
.email()invalidEmailvalue must be a valid email address
.uri()invalidUrivalue must be a valid uri
.uri(allowedSchemes: ['https'])invalidUrivalue must be a valid uri. Allowed scheme is https
.url()invalidUrlvalue must be a valid URL
.url(allowedSchemes: ['http', 'https'])invalidUrlvalue must be a valid URL. Allowed schemes are http, https
.ip()invalidIpvalue must be a valid IP address
.ip(version: IpVersion.v4)invalidIpvalue must be a valid IPv4 address
.uuid()invalidUuidvalue must be a valid uuid
.cuid()invalidCuidvalue must be a valid cuid
.cuid2()invalidCuid2value must be a valid cuid2
.dateTime()invalidDateTimevalue must be a valid date
.emoji()invalidEmojivalue must be a valid emoji
.min(18) on a numbertooSmallvalue must be greater than or equal to 18
.max(100) on a numbertooBigvalue must be less than or equal to 100
.finite()notFinitevalue must be a finite number
.strict() unknown keyunrecognizedKeyrole is not an allowed key
map key validatorinvalidKeyvalue has an invalid key "x"
l.maxDepth exceededtooDeepvalue is nested deeper than 1 levels
fromJson threwfromJsonFailedvalue could not be converted

The name in a message is decided by where the validator runs:

Where Field name
Validated directly, no withName value
Validated directly, after .withName('x') x
A schema field the field key, so email is required
An element of a list field the list’s field name, so tags must be a string at path tags.1
A value of a map field the map’s field name
A key of a map field key, unless the key validator has a withName
A nested schema that is not a map the nested field’s key, so profile must be a map
Validated directly and not a map value must be a map, or the schema’s withName

Messages do not include the path. Read issue.errorPath or the key of the error map for that.

Each failing element of a list reports at its index, and a map reports values at their key and keys as invalidKey issues at the map’s path:

l.list(l.string().required()).validate(['a', 1, null]).errors;
// {1: [value must be a string], 2: [value is required]}
l.map(keyValidator: l.string().email().required(), valueValidator: l.int().required())
.validate({'not-an-email': 'x'})
.errors;
// {: [value has an invalid key "not-an-email"], not-an-email: [value must be an integer]}

Errors and error paths describes the error map in full.