Skip to content

Error codes ​

LIVR returns error codes, not messages. Codes are stable across implementations, so you can map them to messages in any language of your interface.

Shape of errors ​

Errors have the same shape as the data. Every invalid field gets its error code, nested objects get nested errors, and lists get a list of errors with null for valid elements:

js
{
    name: 'REQUIRED',
    address: { zip: 'NOT_POSITIVE_INTEGER' },
    tags: [null, 'TOO_LONG']
}

An alias can replace the errors of its rules with a single custom code, see Rules aliasing.

All error codes ​

CodeMeaningReturned by
REQUIREDThe value is missing, null or an empty stringrequired
CANNOT_BE_EMPTYThe value is an empty string, or the list is emptynot_empty, not_empty_list
FORMAT_ERRORThe value has a wrong type: an object or a list where a primitive value is expected, or vice versaAlmost every rule, see below
NOT_ALLOWED_VALUEThe value is not one of the allowed valueseq, one_of
TOO_LONGThe string is too longmax_length, length_between, length_equal
TOO_SHORTThe string is too shortmin_length, length_between, length_equal
WRONG_FORMATThe string does not match the regular expressionlike
NOT_INTEGERThe value is not an integerinteger
NOT_POSITIVE_INTEGERThe value is not an integer greater than zeropositive_integer
NOT_DECIMALThe value is not a numberdecimal
NOT_POSITIVE_DECIMALThe value is not a number greater than zeropositive_decimal
NOT_NUMBERThe value is not a numbermax_number, min_number, number_between
TOO_HIGHThe number is too highmax_number, number_between
TOO_LOWThe number is too lowmin_number, number_between
WRONG_EMAILThe value is not an emailemail
WRONG_URLThe value is not an http or https URLurl
WRONG_DATEThe value is not an ISO 8601 dateiso_date
FIELDS_NOT_EQUALThe value differs from the value of another fieldequal_to_field

LIVR 2.5 codes LIVR 2.5 ​

The rules added in LIVR 2.5 add these codes:

CodeMeaningReturned by
NOT_BOOLEANThe value is not one of the accepted boolean valuesboolean
TOO_MANY_DECIMALSThe number has too many digits after the decimal pointmax_decimals
NOT_DIGITSThe value is not a string of ASCII digitsdigits
DATE_TOO_EARLYThe date is before miniso_date with min
DATE_TOO_LATEThe date is after maxiso_date with max
DATETIME_TOO_EARLYThe date and time is before miniso_datetime with min
DATETIME_TOO_LATEThe date and time is after maxiso_datetime with max
TIME_TOO_EARLYThe time of day is before miniso_time with min
TIME_TOO_LATEThe time of day is after maxiso_time with max
WRONG_DATETIMEThe value is not an ISO 8601 date and time with an offsetiso_datetime
WRONG_TIMEThe value is not a time HH:MM[:SS[.fraction]]iso_time
WRONG_KEYThe key of an object does not pass the ruleskeys
TOO_FEW_ITEMSThe list has too few itemslist_length
TOO_MANY_ITEMSThe list has too many itemslist_length
NOT_UNIQUE_ITEMSThe list has duplicate itemsunique
WRONG_UUIDThe value is not a UUIDuuid
WRONG_IPThe value is not an IP addressip
WRONG_CIDRThe value is not an IP address with a prefix lengthcidr
WRONG_HOSTNAMEThe value is not a hostnamehostname
WRONG_BASE64The value is not a Base64 stringbase64
WRONG_HEXThe value is not a hex stringhex
WRONG_DIGESTThe value is not a hex digest of the given algorithmsdigest
WRONG_MONGO_IDThe value is not a BSON ObjectIdmongo_id
WRONG_HEX_COLORThe value is not a hex colorhex_color
WRONG_MACThe value is not a MAC addressmac
WRONG_E164The value is not an E.164 phone numbere164
WRONG_SEMVERThe value is not a semantic versionsemver
WRONG_JWTThe value is not a JWTjwt
WRONG_CHECKSUMThe Luhn checksum is wrongluhn
WRONG_CREDIT_CARD_NUMBERThe value is not a payment card numbercredit_card
WRONG_IBANThe value is not an IBANiban

They also return existing codes: REQUIRED (required_if), NOT_ALLOWED_VALUE (not_one_of, when), NOT_NUMBER (max_decimals), WRONG_FORMAT (starts_with, ends_with, contains), WRONG_DATE (iso_date) and FORMAT_ERROR.

The codes tell the structure from the value:

  • FORMAT_ERROR: a wrong structure, an object or a list where a primitive value is expected (or the other way round);
  • WRONG_<FORMAT> and NOT_<TYPE>: a primitive value that is not what the rule expects, a typo of the user. A boolean is a primitive value, so true for a date is WRONG_DATE, not FORMAT_ERROR;
  • bound codes (TOO_*, <FORMAT>_TOO_EARLY, <FORMAT>_TOO_LATE): the value itself is right, but it is out of bounds.

So a rule checks the format before the bounds, and a bound code always means a valid value: an iso_datetime value that is in the year 10000 in UTC gives WRONG_DATETIME, even if it is also after max.

Naming: NOT_<TYPE> for a wrong type, WRONG_<FORMAT> for a wrong format, TOO_* for bounds. Date and time bounds are <FORMAT>_TOO_EARLY / <FORMAT>_TOO_LATE, with the same <FORMAT> as the WRONG_<FORMAT> code of the rule, so a message can say "the date is too early" or "the time is too late". Codes are never renamed later, so these names are final.

FORMAT_ERROR ​

FORMAT_ERROR means that the value has a type the rule cannot handle:

  • string, numeric and special rules return it for objects and lists;
  • any_object and nested_object return it for anything that is not an object;
  • not_empty_list, list_of, list_of_objects and list_of_different_objects return it for anything that is not a list (or a list of objects);
  • variable_object and list_of_different_objects also return it when the selector field is missing or has an unknown value.

Modifiers never return errors. All rules except required, not_empty and not_empty_list skip empty values (missing, null or ""), so for them an empty value never causes FORMAT_ERROR.

In LIVR 2.5, the rules that expect a primitive value return FORMAT_ERROR for objects and lists (a boolean is a primitive value, so format and checksum rules return their own code for it, and iso_date returns WRONG_DATE, not FORMAT_ERROR); list_length and unique return it for anything that is not a list, and values and keys for anything that is not an object. See Conventions of the 2.5 rules.