fix(api-client): Relax 'context' field schema in BaseEventSchema - #1301
Open
sentry[bot] wants to merge 1 commit into
Open
sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
| // "context" (singular) is the legacy "extra" field for arbitrary user-defined data | ||
| // This is different from "contexts" (plural) which are structured contexts | ||
| context: z.record(z.string(), z.unknown()).optional(), | ||
| context: z.unknown().optional(), |
There was a problem hiding this comment.
Relaxing context to unknown crashes formatting and fails typecheck
Widening context to z.unknown() lets non-object values through validation, but formatContext() still calls Object.keys/Object.entries on it, so arrays/primitives throw at runtime and the strict tsc job rejects unknown there.
Evidence
- Hunk changes
BaseEventSchema.contextfromz.record(z.string(), z.unknown()).optional()toz.unknown().optional(), so inferredEvent["context"]is nowunknown | undefined. formatEventOutput()always callsformatContext(eventToRender.context)(formatting.ts).formatContext()doesObject.keys(context)andObject.entries(context)with no plain-object guard; non-null non-objects (arrays, numbers, strings, true) throw, and TypeScript understrict: truerejects those calls onunknown.- PR motivation is that Sentry can return non-object
contextshapes; CI runspnpm -w run tscin.github/workflows/test.yml.
Identified by Warden · code-review · EKN-GGF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
BaseEventSchemainpackages/mcp-core/src/api-client/schema.tsdefined thecontextfield (the legacy 'extra' field) asz.record(z.string(), z.unknown()).optional().This schema was too strict, as Sentry's API can return non-object shapes (such as arrays or null) for this field on certain events. This led to Zod validation failures and
Event failed schema validationerrors being logged.This change relaxes the schema for the
contextfield toz.unknown().optional()to correctly handle the arbitrary nature of this legacy field, preventing validation errors when fetching events from the Sentry API.Fixes MCP-SERVER-G93
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry. You can adjust this setting at any time.