fix(validation): throw ValidationError not RangeError on invalid date comparison - #5281
Open
devteamaegis wants to merge 1 commit into
Open
Conversation
…eGte/dateLte comparison date is invalid
devteamaegis
force-pushed
the
fix/date-validators-invalid-comparison-date
branch
from
June 11, 2026 19:46
fbad811 to
ab0c27f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's broken
The
dateGte/dateLtevalidators throw an uncaughtRangeError: Invalid time valueinstead of aValidationErrorwhen the configured comparison date is unparseable. A validator should only ever throwValidationError, so this leaks a rawRangeErrorup the stack. Hit it by configuring a field with a malformed rule likedateGte:garbage(e.g. a typo in the Headless CMS model editor) — every submission to that field then 500s.Why it happens
When the comparison value can't be parsed,
new Date(value)is an Invalid Date. The comparison isfalse, so control enters the error branch, which builds the message withgteDate.toISOString()— andtoISOString()on an Invalid Date throwsRangeError. The validator crashes while trying to report a validation failure.Fix
Guard with
isNaN(date.getTime())and throw a clearValidationErrorwhen the comparison date is invalid.Test
Added a case to each validator asserting a
ValidationError(notRangeError) on a malformed comparison date; valid in-range/out-of-range behavior is unchanged.