-
-
Notifications
You must be signed in to change notification settings - Fork 126
feat(server): rethrow handler plugin #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @unnoq, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds an experimental RethrowHandlerPlugin that can selectively rethrow errors via a user-provided filter during request handling; includes implementation, tests, documentation, and docs navigation and example updates for Nest integration. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new RethrowHandlerPlugin for the server. This experimental plugin allows specific errors to be re-thrown from the oRPC handler, enabling integration with framework-level error handling mechanisms like those in NestJS or Express. The implementation is robust, using a combination of root and procedure-level interceptors to achieve the desired behavior. The feature is well-tested, with comprehensive unit tests covering various scenarios, including filtering logic and context corruption. New documentation for the plugin has been added, along with updates to the NestJS integration guide to demonstrate its usage. The changes are of high quality and I have no concerns.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/experimental-pino
@orpc/experimental-publisher
@orpc/experimental-publisher-durable-object
@orpc/experimental-ratelimit
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fastify
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/server/src/plugins/rethrow.ts (1)
36-43: Consider makingCONTEXT_SYMBOLreadonly.The symbol is used for internal plugin state coordination. Making it
readonlywould prevent accidental reassignment.- CONTEXT_SYMBOL = Symbol('ORPC_RETHROW_HANDLER_PLUGIN_CONTEXT') + readonly CONTEXT_SYMBOL = Symbol('ORPC_RETHROW_HANDLER_PLUGIN_CONTEXT')
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
apps/content/.vitepress/config.ts(1 hunks)apps/content/docs/openapi/integrations/implement-contract-in-nest.md(2 hunks)apps/content/docs/plugins/rethrow-handler.md(1 hunks)packages/server/src/plugins/index.ts(1 hunks)packages/server/src/plugins/rethrow.test.ts(1 hunks)packages/server/src/plugins/rethrow.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/server/src/plugins/rethrow.test.ts (1)
packages/server/src/builder.ts (2)
handler(273-280)os(336-352)
packages/server/src/plugins/rethrow.ts (4)
packages/server/src/context.ts (1)
Context(1-1)packages/shared/src/value.ts (1)
Value(1-1)packages/server/src/adapters/standard/handler.ts (2)
StandardHandlerInterceptorOptions(23-25)StandardHandlerOptions(27-48)packages/server/src/adapters/standard/plugin.ts (1)
StandardHandlerPlugin(5-8)
🪛 LanguageTool
apps/content/docs/plugins/rethrow-handler.md
[grammar] ~8-~8: Use a hyphen to join words.
Context: ...ul when your framework has its own error handling mechanism (e.g., global excepti...
(QB_NEW_EN_HYPHEN)
[grammar] ~8-~8: Use a hyphen to join words.
Context: ...stead of being handled by the oRPC error handling flow. ## Usage ```ts twoslash...
(QB_NEW_EN_HYPHEN)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Agent
- GitHub Check: lint
- GitHub Check: test
- GitHub Check: publish-commit
- GitHub Check: Cloudflare Pages
🔇 Additional comments (15)
packages/server/src/plugins/index.ts (1)
5-5: LGTM!The new rethrow export is correctly placed in alphabetical order within the barrel file.
apps/content/.vitepress/config.ts (1)
153-153: LGTM!Navigation entry correctly added to the Plugins section with proper link path.
apps/content/docs/plugins/rethrow-handler.md (1)
1-38: LGTM!Clear documentation with a practical usage example. The explanation effectively conveys when and why to use this plugin, particularly for framework integration scenarios like NestJS exception filters.
packages/server/src/plugins/rethrow.test.ts (6)
1-9: LGTM!Good test setup with
vi.clearAllMocks()inbeforeEachto ensure clean state between tests.
10-66: LGTM!Good coverage of the core rethrow behavior - testing both positive (filter returns true → error rethrown) and negative (filter returns false → error handled by oRPC with 500 response) cases. The custom error class test is a nice touch for verifying error identity preservation.
68-102: LGTM!Excellent test case demonstrating the primary use case: distinguishing between
ORPCError(handled by oRPC) and other errors (rethrown to framework). This validates the documented pattern.
104-135: LGTM!Important test verifying that the filter function receives both the error and the interceptor options (including request and context). This ensures users can make context-aware filtering decisions.
137-159: LGTM!Good sanity check ensuring the plugin doesn't interfere with normal (non-error) request handling.
161-195: LGTM!Critical edge case test - verifying graceful degradation when another plugin corrupts the context by removing the plugin's symbol. The 500 response indicates the
TypeErroris being handled by oRPC's error flow.apps/content/docs/openapi/integrations/implement-contract-in-nest.md (2)
225-230: LGTM!Correct imports added for the new plugin integration.
252-260: LGTM!The
RethrowHandlerPluginconfiguration demonstrates a practical NestJS integration pattern, allowing non-oRPC errors to bubble up to NestJS global exception filters for centralized error handling.packages/server/src/plugins/rethrow.ts (4)
1-5: LGTM!Clean imports with appropriate type-only imports where applicable.
6-25: LGTM!Well-documented options interface with a clear example in JSDoc. The
Valuetype provides flexibility for both static boolean values and dynamic filter functions. The internalRethrowHandlerPluginContextcorrectly wraps the error in an object to handle falsy error values.
45-65: LGTM!The root interceptor correctly:
- Creates a fresh plugin context per request
- Injects it into the request context via the unique symbol
- Rethrows the captured error after the pipeline completes (allowing the error to bubble up to the host framework)
The use of
push()ensures this interceptor wraps all other root interceptors, giving it the final say on error handling.
67-87: LGTM!The interceptor correctly:
- Validates the plugin context exists (defensive against context corruption)
- Uses
unshift()to run before other interceptors, catching errors from the entire chain- Applies the filter to determine rethrow behavior
- Returns
{ matched: false, response: undefined }when capturing an error, allowing the pipeline to complete so the root interceptor can perform the actual rethrowThe
awaiton line 76 is correctly noted as important for catching both sync and async errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new experimental RethrowHandlerPlugin that enables selective error rethrowing during request handling, allowing frameworks with built-in error handling mechanisms (e.g., NestJS global exception filters, Express error middleware) to process specific errors instead of oRPC's default error handling flow.
- Implements a plugin that intercepts errors and decides whether to rethrow them based on a filter function
- Adds comprehensive test coverage with multiple scenarios including filter function behavior and context corruption handling
- Includes documentation and integration example for NestJS
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/server/src/plugins/rethrow.ts | Main plugin implementation with interceptor logic for catching and selectively rethrowing errors |
| packages/server/src/plugins/rethrow.test.ts | Comprehensive test suite covering filter behavior, context management, and error handling scenarios |
| packages/server/src/plugins/index.ts | Exports the new rethrow plugin |
| apps/content/docs/plugins/rethrow-handler.md | Documentation page explaining the plugin's purpose and usage |
| apps/content/docs/openapi/integrations/implement-contract-in-nest.md | Adds integration example showing how to use the plugin in NestJS applications |
| apps/content/.vitepress/config.ts | Adds navigation entry for the new plugin documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Deploying orpc with
|
| Latest commit: |
7437ea4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e08ec89c.orpc-1qh.pages.dev |
| Branch Preview URL: | https://feat-server-rethrow-plugin.orpc-1qh.pages.dev |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary by CodeRabbit
New Features
Documentation
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.