Skip to content

refactor(core): migrate MessageV2 errors to Schema-backed named errors#23764

Merged
kitlangton merged 1 commit intodevfrom
kit/session-schema-errors
Apr 22, 2026
Merged

refactor(core): migrate MessageV2 errors to Schema-backed named errors#23764
kitlangton merged 1 commit intodevfrom
kit/session-schema-errors

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Stacked on #23763.

Introduces namedSchemaError(tag, fields) helper that:

  • Builds the error data schema as Schema.Struct(fields).
  • Derives a Zod wire schema with the same { name, data } shape as the original NamedError.create output (so $ref: <Tag> in openapi.json is byte-identical).
  • Returns a class with the same API surface NamedError exposes: static Schema, static isInstance, instance toObject(), constructor takes (data, options?).

Applies the helper to all MessageV2 errors: 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.ts where err.data.message needs an in check now that the discriminated union is precise.

Acceptance check

  • bun typecheck clean.
  • bun run test → 2010 pass / 0 fail.
  • bun dev generate byte-identical to committed packages/sdk/openapi.json.
  • packages/sdk/js/src/v2/gen/types.gen.ts unchanged after bun script/build.ts.

@kitlangton kitlangton force-pushed the kit/session-schema-cursor branch from dc0d77e to ee1edd1 Compare April 22, 2026 03:10
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch 2 times, most recently from b2e84cf to 51334b9 Compare April 22, 2026 03:12
@kitlangton kitlangton force-pushed the kit/session-schema-cursor branch 2 times, most recently from 7d2ea87 to 41daea9 Compare April 22, 2026 03:18
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch from 51334b9 to 63bd01a Compare April 22, 2026 03:18
@kitlangton kitlangton force-pushed the kit/session-schema-cursor branch from 41daea9 to 6998866 Compare April 22, 2026 03:27
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch from 63bd01a to 62d9778 Compare April 22, 2026 03:27
Base automatically changed from kit/session-schema-cursor to dev April 22, 2026 03:28
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.
@kitlangton kitlangton force-pushed the kit/session-schema-errors branch from 62d9778 to 68b3a39 Compare April 22, 2026 03:36
@kitlangton kitlangton merged commit ed802fd into dev Apr 22, 2026
9 checks passed
@kitlangton kitlangton deleted the kit/session-schema-errors branch April 22, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant