-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Return all schema errors #68
Comments
@ozimos Currently Zod returns all the errors it can. For instance if you're validating an object, it will give you all the errors detected and a path to where in the object the error was thrown. Check out the Error Handling section of the docs if you haven't already. If there's a specific instance where Zod is throwing an error too early, please provide some details and a code sample, and I'll look into it. |
Here is a sandbox https://codesandbox.io/s/github/ozimos/zod-error-repro/tree/master/ |
@vriad I know that Zod does return all the errors https://codesandbox.io/s/kind-curie-ilf05?file=/src/index.ts |
@ozimos Looking into your repo now. I've never used React hook form so I'm having some trouble figuring out what's going on. Would it be possible for you to send me the data being validated and the error(s) being returned? Seems unlikely that the library could impact Zod's bahavior. |
I'm working off these examples in the react-hook-form docs some output from the console
|
@vriad In the dump above, I am typing into the form inputs and logging to console at lines 24 and 33 of App.tsx. In the console dump above, there is only one error from zod even when both email and confirmPassword fields are wrong. As soon as I fix the email field the sole error message switches from "Invalid email address." to "Both password and confirmation must match" |
Gotcha. Just looked into the code and Zod doesn't run the custom refinements on an object schema if there was an error earlier when parsing its values. I'll fix this and get back to you. |
I just published zod@1.8 which has far more consistent parsing behavior. Specifically, parsing in executed in two phases:
@ozimos Give this a shot with zod@1.8+ and let me know if you're still encountering issues. |
@vriad I've just encountered some missing errors as seen in #107 I'm building |
How do I get Zod to return all the errors. Currently schema.parse throws on the first error. Something like yup's
{abortEarly: false}
would be niceThe text was updated successfully, but these errors were encountered: