Skip to content

fix(validation): throw ValidationError not RangeError on invalid date comparison - #5281

Open
devteamaegis wants to merge 1 commit into
webiny:nextfrom
devteamaegis:fix/date-validators-invalid-comparison-date
Open

fix(validation): throw ValidationError not RangeError on invalid date comparison#5281
devteamaegis wants to merge 1 commit into
webiny:nextfrom
devteamaegis:fix/date-validators-invalid-comparison-date

Conversation

@devteamaegis

Copy link
Copy Markdown

What's broken

The dateGte / dateLte validators throw an uncaught RangeError: Invalid time value instead of a ValidationError when the configured comparison date is unparseable. A validator should only ever throw ValidationError, so this leaks a raw RangeError up the stack. Hit it by configuring a field with a malformed rule like dateGte: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 is false, so control enters the error branch, which builds the message with gteDate.toISOString() — and toISOString() on an Invalid Date throws RangeError. The validator crashes while trying to report a validation failure.

Fix

Guard with isNaN(date.getTime()) and throw a clear ValidationError when the comparison date is invalid.

Test

Added a case to each validator asserting a ValidationError (not RangeError) on a malformed comparison date; valid in-range/out-of-range behavior is unchanged.

@devteamaegis
devteamaegis force-pushed the fix/date-validators-invalid-comparison-date branch from fbad811 to ab0c27f Compare June 11, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant