zod
zod copied to clipboard
Wrap preprocess with try-catch to provide better information on error
Before this fix, any errors during preprocess would result in an error that doesn't provide a lot of debug information. For example, the path where the error happened was not provided by Zod. This change will make sure that even errors during preprocess are translated to ZodError with useful metadata about the error.
Solves issue #2724
Deploy Preview for guileless-rolypoly-866f8a ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | fbadf6ac1c98345dec79641dbc19bd5a77a3405c |
| Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/65ec29e97042e10009fb09b1 |
| Deploy Preview | https://deploy-preview-3314--guileless-rolypoly-866f8a.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Zod's currently policy is to let errors in refinements, transforms, and preprocess propagate up the call stack. The goal of ZodError is to expose validation errors. In my opinion, an uncaught error inside .preprocess() is a bug and doesn't indicate a schema validation issue. In this scenario, I think it's actually desirable for these errors to propagate normally, for debugging reasons. Ultimately it's up to the user to catch and handle errors inside these callbacks.
I'm open to hearing counter-arguments. If this was going to change, the behavior would have to be consistent among refine/transform/preprocess.