Skip to content

feat(effect): add catchORPCError, catchORPCErrorCode and catchORPCErrorCodes utils - #1766

Merged
dinwwwh merged 2 commits into
middleapi:mainfrom
dinwwwh:claude/catch-orpc-error-utils-2e8418
Aug 3, 2026
Merged

feat(effect): add catchORPCError, catchORPCErrorCode and catchORPCErrorCodes utils#1766
dinwwwh merged 2 commits into
middleapi:mainfrom
dinwwwh:claude/catch-orpc-error-utils-2e8418

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 2, 2026

Copy link
Copy Markdown
Member

Adds catchORPCError, catchORPCErrorCode and catchORPCErrorCodes to @orpc/experimental-effect for recovering from ORPCError failures in an effect's error channel. Recovered errors are excluded from the resulting effect's error channel, and non-matching failures re-fail with their original cause.

Details

  • All utilities support data-first and data-last (.pipe) styles, following Effect's dual convention.
  • Handlers receive the matching errors narrowed from the error channel, with per-code data types preserved.
  • catchORPCErrorCode and catchORPCErrorCodes mirror Effect's catchTag/catchTags naming and suggest/restrict codes to those present in the error channel.
  • Defects and interruptions are not caught.

Testing

  • Logic tests cover all call styles, code matching/mismatch, partial and undefined handler maps, non-ORPCError passthrough, defects, successes, and re-failing handlers — 100% statement/branch/function/line coverage on the new module.
  • Type tests verify handler narrowing, error-channel exclusion, requirement merging, custom codes, and rejection of out-of-channel codes and map keys.
  • Docs: new "Catching ORPCErrors" section on the Effect integration page.

@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 2:51pm

@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@1766

@orpc/arktype

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

@orpc/bun

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

@orpc/client

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

@orpc/cloudflare

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

@orpc/contract

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

@orpc/experimental-effect

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

@orpc/evlog

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

@orpc/json-schema

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

@orpc/nest

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

@orpc/next

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

@orpc/openapi

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

@orpc/opentelemetry

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

@orpc/pinia-colada

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

@orpc/pino

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

@orpc/publisher

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

@orpc/ratelimit

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

@orpc/server

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

@orpc/shared

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

@orpc/swr

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

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/zod

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

commit: 8edc5b3

@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!

@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/catch-orpc-error-utils-2e8418 (8edc5b3) with main (240215c)

Open in CodSpeed

@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 — adds catchORPCError and catchORPCErrorByCode to @orpc/experimental-effect for recovering from ORPCError failures in an effect's error channel.

  • catchORPCError / catchORPCErrorByCode (error.ts) — two Function.dual utilities wrapping Effect.catchIf with an instanceof ORPCError type guard, following the same pattern as the existing succeedOnORPCError in handler.ts. catchORPCError handles every ORPCError code; catchORPCErrorByCode narrows by code and constrains the code argument to the codes present in the error channel.
  • Runtime tests (error.test.ts) — 12 tests covering data-first/data-last call styles, code matching and mismatch, non-ORPCError passthrough, defects, successes, and re-failing handlers. 100% statement/branch/function/line coverage.
  • Type tests (error.test-d.ts) — verifies handler narrowing, error-channel exclusion, requirement merging, never handler for ORPCError-free channels, custom codes, and rejection of out-of-channel codes.
  • Barrel re-export (index.ts) — adds export * from './error'; export test updated.
  • Docs (effect.md) — new "Catching ORPCErrors" section with import and usage examples.

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

@dinwwwh dinwwwh changed the title feat(effect): add catchORPCError and catchORPCErrorByCode utils feat(effect): add catchORPCError, catchORPCErrorCode and catchORPCErrorCodes utils Aug 2, 2026

@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 — renames catchORPCErrorByCode to catchORPCErrorCode and adds catchORPCErrorCodes for multi-code recovery.

  • Renamed catchORPCErrorByCodecatchORPCErrorCode — aligns with Effect's catchTag naming convention, dropping the By prefix. All call sites, tests, type tests, and docs updated.
  • Added catchORPCErrorCodes — accepts a map of code-to-handler entries, catching each ORPCError with the matching handler and excluding handled codes from the resulting error channel. Supports undefined handlers (treated as no-op for that code). Both data-first and data-last styles via Function.dual(2, ...).
  • New tests — 7 runtime tests covering matching/mismatching codes, undefined handlers, non-ORPCError passthrough, successes, and re-failing handlers. 4 type tests covering narrowing, channel exclusion, and code-key restriction.

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

@dinwwwh
dinwwwh merged commit d9d031f into middleapi:main Aug 3, 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