Skip to content

Conversation

serhiitroinin
Copy link

Summary

This PR fixes the confusing error messages when validating special numeric values (Infinity, NaN) and invalid dates with Zod schemas. Closes #5186

Problem

When parsing Infinity with z.number(), the error message was: Invalid input: expected number, received number

This was confusing because it appeared to say the same type was both expected and received.

Solution

  • Update parsedType() function in all locales to detect Infinity using Number.isFinite()
  • Modify error message generation to check for issue.received field before falling back to parsedType()
  • Update error message generation across all locale files to properly display:
    • "received Infinity" for infinite values
    • "received NaN" for NaN values
    • "received Invalid Date" for invalid dates

Previously, parsing Infinity with z.number() showed the confusing error:
"Invalid input: expected number, received number"

This fix updates error message generation to properly display:
- "received Infinity" for infinite values
- "received NaN" for NaN values
- "received Invalid Date" for invalid dates
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.

[V4] Confusing error message with zod.number and Infinity

1 participant