feat(contract): add failed data to ValidationError for debugging - #949
Conversation
Store original validation input/output in ValidationError.data to improve error debugging and troubleshooting capabilities.
WalkthroughAdds an optional data payload to ValidationError and propagates it across validation failure paths: event iterator value validation and server-side input/output validation. Updates tests to assert the cause contains the failing value in data. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Server
participant Validator
participant Error as ORPCError
Client->>Server: Call procedure(input)
Server->>Validator: validate(input)
alt Input invalid
Validator-->>Server: issues
Server->>Error: ORPCError(BAD_REQUEST, cause=ValidationError{message, issues, data=input})
Server-->>Client: Error
else Input valid
Server->>Server: execute()
Server->>Validator: validate(output)
alt Output invalid
Validator-->>Server: issues
Server->>Error: ORPCError(INTERNAL_SERVER_ERROR, cause=ValidationError{message, issues, data=output})
Server-->>Client: Error
else Output valid
Server-->>Client: Result
end
end
sequenceDiagram
autonumber
participant Producer as Async Generator
participant Iterator as eventIterator
participant Validator
participant Error as ORPCError
loop For each yielded value
Producer-->>Iterator: value
Iterator->>Validator: validate(value)
alt Value invalid
Validator-->>Iterator: issues
Iterator->>Error: ORPCError(EVENT_ITERATOR_VALIDATION_FAILED, cause=ValidationError{message, issues, data=value})
Iterator-->>Consumer: throw Error
else Value valid
Iterator-->>Consumer: yield value
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Summary of Changes
Hello @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 enhances the debugging experience by embedding the problematic data directly within ValidationError instances. This change allows developers to quickly inspect the exact input or output that led to a validation error, streamlining the troubleshooting process for contract and procedure validation failures.
Highlights
- Error Data Inclusion: The
ValidationErrorclass and its options interface now include an optionaldatafield to store the original input or output that caused the validation failure. - Enhanced Debugging: The original data that failed validation is now passed into the
ValidationErrorconstructor inevent-iterator.tsandprocedure-client.ts, significantly improving debugging capabilities. - Test Coverage: A new test case has been added to
event-iterator.test.tsto ensure thedatafield ofValidationErrorcorrectly captures the failed input.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request enhances error debugging by adding the failed data to ValidationError. The implementation is solid and correctly applied across the codebase. I've suggested a small refactoring to make the message property on ValidationError optional. This would reduce code duplication where ValidationError is nested within another error that already carries a descriptive message, improving overall maintainability.
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@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-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.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/contract/src/error.ts (2)
8-11: Document PII/size/serialization caveats fordata.Carrying raw input/output increases risk of leaking secrets and blowing up logs/JSON (BigInt, cycles, huge payloads). Add guidance here to treat
dataas debug-only and to redact/limit size.Apply this doc tweak:
/** * @todo require this field in v2 + * Note: May contain sensitive data. Prefer using only in development or with redaction. + * Ensure values are JSON-serializable and size-limited to avoid log/transport issues. */
27-27: Consider snapshotting to avoid post-throw mutation (optional).If callers mutate
options.dataafter throw, the error’s view changes. If that matters, snapshot defensively (e.g., shallow clone) when reasonable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
packages/contract/src/error.ts(2 hunks)packages/contract/src/event-iterator.test.ts(1 hunks)packages/contract/src/event-iterator.ts(1 hunks)packages/server/src/procedure-client.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/server/src/procedure-client.ts (2)
packages/contract/src/error.ts (1)
ValidationError(19-29)packages/server/src/index.ts (1)
ValidationError(26-26)
⏰ 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). (3)
- GitHub Check: test
- GitHub Check: lint
- GitHub Check: publish-commit
🔇 Additional comments (2)
packages/contract/src/error.ts (1)
21-21: Property shape is fine.Having
readonly data: unknown(possiblyundefined) is acceptable and keeps usage simple.packages/contract/src/event-iterator.test.ts (1)
48-48: LGTM: asserts failing value is carried in cause.data.Matches the new behavior and improves debuggability.
Store original validation input/output in ValidationError.data to improve error debugging and troubleshooting capabilities.
Summary by CodeRabbit