Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch coerce errors #3927

Open
maxandron opened this issue Dec 28, 2024 · 0 comments
Open

catch coerce errors #3927

maxandron opened this issue Dec 28, 2024 · 0 comments

Comments

@maxandron
Copy link

Hello,

Discovering coercion errors during safeParse would be nice. Which goes hand in hand with making the error thrown from parse a ZodError.

Example:

const maybeBigInt = z.string().pipe(z.coerce.bigint());

// works well - returns 0n
maybeBigInt.parse('0');

// Returns ZodError as expected
maybeBigInt.safeParse({});

// Throws "SyntaxError"
maybeBigInt.safeParse('not a number');

Thank you and let me know if you want me to tackle it with a PR.

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

No branches or pull requests

1 participant