-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(integrations): Add zod integration #11144
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
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!
I created a docs issue for this as we don't have docs for that yet: getsentry/sentry-docs#14626 |
import { defineIntegration } from '../integration'; | ||
|
||
interface ZodErrorsOptions { | ||
key?: string; |
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.
@scttcper I know this PR is quite old already but I just discovered the integration in the code and started creating docs for it.
I stumbled upon the option key
which is actually not used in the integration. Should this be deleted or should this be the key under which Zod error details will be attached to the event's extra data? (now "zoderror.issues"
)
'zoderror.issues': flattenedIssues.slice(0, limit), |
## DESCRIBE YOUR PR Documents getsentry/sentry-javascript#11144 closes #14626 ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
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


