Skip to content

feat(contract): validate data in error factory constructor - #1765

Merged
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:claude/error-factory-constructor-validation-9d8e1f
Aug 2, 2026
Merged

feat(contract): validate data in error factory constructor#1765
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:claude/error-factory-constructor-validation-9d8e1f

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 2, 2026

Copy link
Copy Markdown
Member

The error factory constructor now validates data against the schema instead of only validating during instanceof checks. Invalid data throws a ValidationError (with issues and invalidData, same class used by input/output validation), and the validated schema output is what gets stored on the error - so schema transforms like zod's unknown-key stripping now apply to constructed errors.

Behavior

  • Since both the constructor and instanceof validate synchronously, the sync-schema requirement is now factory-wide: an async data schema throws the same TypeError from either path, with a unified message.
  • Factories without a data schema are unchanged - no validation runs.

Docs

  • The sync-schema warning moved from the instanceof subsection to the main Error Factory section and now also covers the constructor's ValidationError behavior; JSDoc updated to match.

Testing

  • New constructor cases: validated value is stored (proven via zod key stripping), invalid/missing data throws ValidationError, async schemas throw in the constructor.
  • Contract, server procedure-client, OpenAPI generator, and e2e data-transfer suites pass; pnpm type:check and eslint are clean.

The error factory constructor now validates data against the schema:
invalid data throws a ValidationError and the validated schema output is
what gets stored on the error. Since both the constructor and instanceof
now validate synchronously, the sync-schema requirement is factory-wide;
the async-schema TypeError is unified into one shared helper and the
docs warning moved from the instanceof subsection to the main Error
Factory section.
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 2, 2026 1:57pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 2, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1765

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1765

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1765

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1765

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1765

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1765

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1765

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1765

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1765

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1765

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1765

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1765

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1765

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1765

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1765

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1765

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1765

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1765

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1765

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1765

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1765

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1765

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1765

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1765

commit: e912b10

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Constructor data validation — the error factory constructor now validates data through a shared validateData helper, throwing ValidationError on invalid input and storing the schema-transformed output. Async schemas throw a TypeError with a consistent message across both constructor and instanceof paths.
  • Deduplicated async-schema check — the Symbol.hasInstance path now delegates to the same validateData helper instead of inlining an identically-shaped block. The dataSchema guard on the instanceof path also avoids an unnecessary passthrough-schema call for factories without a schema.
  • Docs sync — the sync-schema warning moved from the old instanceof-only subsection to the Error Factory options JSDoc and the doc page, and the @param tags were removed (the TS types already cover them).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@codspeed-hq

codspeed-hq Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing dinwwwh:claude/error-factory-constructor-validation-9d8e1f (e912b10) with main (725972b)

Open in CodSpeed

@dinwwwh
dinwwwh merged commit 240215c into middleapi:main Aug 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant