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
Caught errors are not distinguishable from uncaught errors #1839
Labels
bug-confirmed
Bug report that is confirmed
Comments
This seems like a bug to me. I don't think const schema = z.object( {
stringProp: z.string(),
numberPropWithCatch: z.number().catch( 0 ),
} )
const result = schema.safeParse( {
stringProp: {},
numberPropWithCatch: '',
} )
!result.success && console.log( result.error.flatten() )
// {
// formErrors: [],
// fieldErrors: {
// stringProp: [ "Expected string, received object" ],
// numberPropWithCatch: [ "Expected number, received string" ]
// }
// } |
Agreed. Good catch! |
maxArturo
added a commit
to maxArturo/zod
that referenced
this issue
Jan 23, 2023
maxArturo
added a commit
to maxArturo/zod
that referenced
this issue
Jan 23, 2023
maxArturo
added a commit
to maxArturo/zod
that referenced
this issue
Jan 23, 2023
@lewischa @JacobWeisenburger took a crack at this on #1926. Let me know what you think! |
colinhacks
pushed a commit
that referenced
this issue
Jan 29, 2023
Thank you all! Is there a "dev" or "beta" release that includes that fix, or would you recommend forking/cloning? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In v3.20.x errors handled via the
catch
operator are logged along with errors that actually cause the parsing to fail. This makes it difficult to differentiate "fatal", uncaught errors from non-fatal, caught/handled errors. This isn't a huge deal in smaller schemas, but becomes very tedious with larger ones.Is there a way to suppress caught errors from
parse
andsafeParse
, or perhaps mark them as caught?Example
See the interactive example on Stackblitz, but here's the code for a minimal reproduction:
Running this code results in an error as expected, but notice how both the fatal and caught errors are displayed:
The text was updated successfully, but these errors were encountered: