Skip to content

Fix JSON-RPC handler losing revert data for non-ProviderError errors#8061

Merged
ChristopherDedominici merged 2 commits intomainfrom
fix-loss-of-revert-data
Mar 16, 2026
Merged

Fix JSON-RPC handler losing revert data for non-ProviderError errors#8061
ChristopherDedominici merged 2 commits intomainfrom
fix-loss-of-revert-data

Conversation

@ChristopherDedominici
Copy link
Copy Markdown
Contributor

@ChristopherDedominici ChristopherDedominici commented Mar 13, 2026

Summary

  • Fix JSON-RPC handler losing revert data (txHash, returnData) for non-ProviderError errors (e.g. SolidityError)
  • Add unit test verifying revert data preservation through the JSON-RPC HTTP layer

This bug only affects the Hardhat node (HTTP) because it is exclusive to the JSON-RPC serialization path, whereas in-process EDR passes errors as raw JavaScript objects, bypassing serialization entirely.

Problem

_handleError in handler.ts wrapped non-ProviderError errors in InternalError before calling extractTxHash() and extractReturnData(). Since InternalError doesn't carry .data or .transactionHash, all revert information was lost in the JSON-RPC response.

This broke every revert-checking assertion (.revertedWithCustomError(), .revertedWith(), .revertedWithPanic(), etc.) when running tests against hardhat node over HTTP/WebSocket. In-process EDR tests were unaffected.

Fix

Move the two extraction calls above the wrapping to preserve the info.

Copilot AI review requested due to automatic review settings March 13, 2026 11:11
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: c03f647

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes JSON-RPC error handling so revert metadata (transactionHash / revert data) is preserved even when the thrown error is not a ProviderError (e.g., Solidity-style errors), ensuring revert assertions continue to work over HTTP/WebSocket.

Changes:

  • Extract txHash and returnData from the original error before wrapping non-ProviderError errors into InternalError.
  • Add a unit test that simulates a non-ProviderError carrying .data and .transactionHash and asserts the JSON-RPC response preserves both.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
v-next/hardhat/src/internal/builtin-plugins/node/json-rpc/handler.ts Moves revert data extraction ahead of non-ProviderError wrapping to avoid losing metadata.
v-next/hardhat/test/internal/builtin-plugins/node/json-rpc/handler.ts Adds coverage ensuring revert metadata survives the JSON-RPC HTTP layer for non-ProviderError errors.

You can also share your feedback on Copilot code review. Take the survey.

@ChristopherDedominici ChristopherDedominici added no docs needed This PR doesn't require links to documentation and removed status:triaging labels Mar 13, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Hardhat Mar 13, 2026
@ChristopherDedominici ChristopherDedominici moved this from Backlog to In Progress in Hardhat Mar 13, 2026
@ChristopherDedominici ChristopherDedominici marked this pull request as ready for review March 13, 2026 14:32
@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit acb1384 Mar 16, 2026
215 of 216 checks passed
@ChristopherDedominici ChristopherDedominici deleted the fix-loss-of-revert-data branch March 16, 2026 16:25
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Hardhat Mar 16, 2026
@github-actions github-actions Bot mentioned this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants