refactor(core): migrate MessageV2 errors to Schema-backed named errors#23764
Merged
kitlangton merged 1 commit intodevfrom Apr 22, 2026
Merged
refactor(core): migrate MessageV2 errors to Schema-backed named errors#23764kitlangton merged 1 commit intodevfrom
kitlangton merged 1 commit intodevfrom
Conversation
dc0d77e to
ee1edd1
Compare
b2e84cf to
51334b9
Compare
7d2ea87 to
41daea9
Compare
51334b9 to
63bd01a
Compare
41daea9 to
6998866
Compare
63bd01a to
62d9778
Compare
Adds namedSchemaError helper that preserves the existing NamedError API surface (.Schema, .isInstance, .toObject, new X({...}, { cause })) while backing the schema with Schema.Struct under the hood. Wire shape stays {name, data}, so the OpenAPI output is byte-identical.
62d9778 to
68b3a39
Compare
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.
Stacked on #23763.
Introduces
namedSchemaError(tag, fields)helper that:Schema.Struct(fields).{ name, data }shape as the originalNamedError.createoutput (so$ref: <Tag>in openapi.json is byte-identical).Schema, staticisInstance, instancetoObject(), constructor takes(data, options?).Applies the helper to all
MessageV2errors:OutputLengthError,AbortedError,StructuredOutputError,AuthError,APIError,ContextOverflowError.Downstream callers (retry.ts, processor.ts, prompt.ts, message-v2.ts internal, github.ts, etc.) keep working untouched except for one narrowing nit in
cli/cmd/github.tswhereerr.data.messageneeds anincheck now that the discriminated union is precise.Acceptance check
bun typecheckclean.bun run test→ 2010 pass / 0 fail.bun dev generatebyte-identical to committedpackages/sdk/openapi.json.packages/sdk/js/src/v2/gen/types.gen.tsunchanged afterbun script/build.ts.