Skip to content

feat(contract): add failed data to ValidationError for debugging - #949

Merged
dinwwwh merged 1 commit into
mainfrom
feat/contract/access-failed-data-to-ValidationError
Aug 31, 2025
Merged

feat(contract): add failed data to ValidationError for debugging#949
dinwwwh merged 1 commit into
mainfrom
feat/contract/access-failed-data-to-ValidationError

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 30, 2025

Copy link
Copy Markdown
Member

Store original validation input/output in ValidationError.data to improve error debugging and troubleshooting capabilities.

Summary by CodeRabbit

  • New Features
    • Validation errors now include the offending data payload, improving debuggability for failed input/output validation and event iterator values. Existing error messages and codes are unchanged.
  • Tests
    • Added test coverage to assert the data payload is present on validation error causes.

Store original validation input/output in ValidationError.data to improve
error debugging and troubleshooting capabilities.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 30, 2025
@coderabbitai

coderabbitai Bot commented Aug 30, 2025

Copy link
Copy Markdown

Walkthrough

Adds 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

Cohort / File(s) Summary of changes
Contract error payload extension
packages/contract/src/error.ts
Introduced optional data?: unknown in ValidationErrorOptions and readonly data on ValidationError; constructor assigns options.data.
Event iterator validation payload
packages/contract/src/event-iterator.ts, packages/contract/src/event-iterator.test.ts
On validation failure, constructs ValidationError with data: value; test asserts cause.data equals the failing item.
Server procedure validation payloads
packages/server/src/procedure-client.ts
Includes failing input/output as data in ValidationError when validation fails for BAD_REQUEST and INTERNAL_SERVER_ERROR paths.

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
Loading
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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size:M

Poem

A hop, a skip, a payload new,
I tuck the data in errors too.
When inputs trip or outputs stray,
I carry clues along the way.
With ears up high I debug fast—
A bun who logs the failing past. 🐇✨

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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/contract/access-failed-data-to-ValidationError

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vercel

vercel Bot commented Aug 30, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
orpc Ready Ready Preview Comment Aug 30, 2025 3:08am

@gemini-code-assist gemini-code-assist 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.

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 ValidationError class and its options interface now include an optional data field 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 ValidationError constructor in event-iterator.ts and procedure-client.ts, significantly improving debugging capabilities.
  • Test Coverage: A new test case has been added to event-iterator.test.ts to ensure the data field of ValidationError correctly 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

  1. 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

codecov Bot commented Aug 30, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@gemini-code-assist gemini-code-assist 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.

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.

Comment thread packages/contract/src/error.ts
Comment thread packages/contract/src/error.ts
Comment thread packages/contract/src/event-iterator.ts
Comment thread packages/server/src/procedure-client.ts
Comment thread packages/server/src/procedure-client.ts
@pkg-pr-new

pkg-pr-new Bot commented Aug 30, 2025

Copy link
Copy Markdown
More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@949

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@949

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@949

@orpc/json-schema

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

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@949

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@949

@orpc/react

npm i https://pkg.pr.new/@orpc/react@949

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@949

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@949

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@949

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@949

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@949

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@949

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@949

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@949

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@949

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@949

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@949

@orpc/zod

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

commit: 53efb4d

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/contract/src/error.ts (2)

8-11: Document PII/size/serialization caveats for data.

Carrying raw input/output increases risk of leaking secrets and blowing up logs/JSON (BigInt, cycles, huge payloads). Add guidance here to treat data as 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.data after 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 216e5a5 and 53efb4d.

📒 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 (possibly undefined) 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.

Comment thread packages/contract/src/event-iterator.ts
Comment thread packages/server/src/procedure-client.ts
Comment thread packages/server/src/procedure-client.ts
@dinwwwh
dinwwwh merged commit f437dcb into main Aug 31, 2025
11 checks passed
@dinwwwh
dinwwwh deleted the feat/contract/access-failed-data-to-ValidationError branch June 22, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant