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
feat(integrations): Add zod integration #11144
Conversation
This adds a [Zod](https://github.com/colinhacks/zod) integration to sentry that adds better support for ZodError issues. Currently, the ZodError message is a formatted json string that gets truncated and the full list of issues are lost. - Adds the full list of issues to `extras['zoderror.issues']`. - Replaces the error message with a simple string.
size-limit report 📦
|
Hey @scttcper do you mind resolving merge conflicts (rebasing on develop), then I'll take a look - thank you! (and sorry for late response, got a bit lost there...) |
# Conflicts: # packages/node/src/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
We need to remember also adding this to the docs as a non-default integration, once v8 ships.
packages/utils/src/zod-errors.ts
Outdated
* This doesn't display well in the Sentry UI. Replace it with something shorter. | ||
*/ | ||
function formatIssueMessage(zodError: ZodError): string { | ||
const formError = zodError.flatten(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend against relying on .flatten
here as it's liable to change in Zod 4. Instead consider iterating over the .issues
array.
declare let err: z.ZodError;
const errorKeyMap = new Set<string | number | symbol>();
for (const iss of err.issues) {
if (iss.path) errorKeyMap.add(iss.path[0]);
}
const errorKeys = Array.from(errorKeyMap);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could do these two changes, I'd be happy to merge:
- Just move all the code in the integration, no need to split this across core & utils.
- Apply the feedback that was given about
flatten
, sounds good to me to be future proof there.
Thanks a lot!
@mydea i think this is ready to go. I assume you'll merge it? I'm not up to date on what's going on with the sdk v8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks so much for this PR!
This adds a Zod integration to sentry that adds better support for ZodError issues. Currently, the ZodError message is a formatted json string that gets truncated and the full list of issues are lost.
extras['zoderror.issues']
.before
after