-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Zod 4 enum error messages omitting "received X" part #4339
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
Comments
The change you're referring to was intentional. Zod has a policy of not logging any user input by default, which is (partially) why there's no As a compromise, you're now able to access the const myEnum = z.enum(["a", "b", "c"], {
error: (iss): string => `Expected ${Object.values(myEnum.def.entries)}, received ${iss.input}`,
});
myEnum.parse("d");
// => 'Expected a,b,c, received d' Thanks for the idea! I've loosened the input type for -- Re compat: The most recent betas have been significantly restructured to make it easier for projects/libraries to incrementally migrate to Zod 4. Details here: #4364 |
Thanks @colinhacks ! ❤ |
@colinhacks thanks for the workaround with:
is there a way, somehow to apply this globally in v4? with this method it looks like we'd have to assign this param to every enum definition for the intended functionality |
I wanted to check out the new
prettifyError
utility of Zod 4. When checking its implementation in@zod/core
, I realized it is also compatible with Zod 3; except for a type-cast.To prove it, I ran the following script:
I noticed a small behavior difference.
Zod 3:
Zod 4:
My questions:
The text was updated successfully, but these errors were encountered: