feat(effect): add catchORPCError, catchORPCErrorCode and catchORPCErrorCodes utils - #1766
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/bun
@orpc/client
@orpc/cloudflare
@orpc/contract
@orpc/experimental-effect
@orpc/evlog
@orpc/json-schema
@orpc/nest
@orpc/next
@orpc/openapi
@orpc/opentelemetry
@orpc/pinia-colada
@orpc/pino
@orpc/publisher
@orpc/ratelimit
@orpc/server
@orpc/shared
@orpc/swr
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ 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) — twoFunction.dualutilities wrappingEffect.catchIfwith aninstanceof ORPCErrortype guard, following the same pattern as the existingsucceedOnORPCErrorinhandler.ts.catchORPCErrorhandles every ORPCError code;catchORPCErrorByCodenarrows 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,neverhandler for ORPCError-free channels, custom codes, and rejection of out-of-channel codes. - Barrel re-export (
index.ts) — addsexport * from './error'; export test updated. - Docs (
effect.md) — new "Catching ORPCErrors" section with import and usage examples.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…dd catchORPCErrorCodes
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — renames catchORPCErrorByCode to catchORPCErrorCode and adds catchORPCErrorCodes for multi-code recovery.
- Renamed
catchORPCErrorByCode→catchORPCErrorCode— aligns with Effect'scatchTagnaming convention, dropping theByprefix. 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. Supportsundefinedhandlers (treated as no-op for that code). Both data-first and data-last styles viaFunction.dual(2, ...). - New tests — 7 runtime tests covering matching/mismatching codes,
undefinedhandlers, non-ORPCError passthrough, successes, and re-failing handlers. 4 type tests covering narrowing, channel exclusion, and code-key restriction.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Adds
catchORPCError,catchORPCErrorCodeandcatchORPCErrorCodesto@orpc/experimental-effectfor recovering fromORPCErrorfailures 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
.pipe) styles, following Effect'sdualconvention.catchORPCErrorCodeandcatchORPCErrorCodesmirror Effect'scatchTag/catchTagsnaming and suggest/restrict codes to those present in the error channel.Testing
ORPCErrorpassthrough, defects, successes, and re-failing handlers — 100% statement/branch/function/line coverage on the new module.