Potentially breaking: Make null validation errors consistent across schema #1982
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, schema that parse to invalid values like
InvalidDate
orNaN
always tripped thetypeError
validation before the nullability error. This was the due to typeError no longer firing onnull
values, with the expectation that it would always hit the newer nullability check.This change fixes the issue for Number and Date schema, so that they act the same as String and other schema, where
null
values do not trigger the typeError validation. The consequence of this is that castingnull
values for non-nullable number schema, now returnnull
instead ofNaN
and dates, returnnull
instead ofInvalidDate
. Essentially these schema will not fruitlessly attempt to coercenull
into a number or date anymore.I am marking this as a bug fix since it is, and as with most bug fixes, could also be considered a breaking change. I'm going to optimistically not cut a v2 for this. If you have unexpected changes it is likely due to number/date schema hitting different validation errors (nullability).
Previously for these schema it was common practice to change the
typeError
for these schema to something like"this is required"
assuming the issue was due to invalidnull
s. NOW the schema will show thelocale.notNull
message, so if you may want to adjust that to something more user friendly if you surface default locale messages to users (we don't generally recommend that).