Skip to content
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

ContractFunctionRevertedError does not expose raw revert data #3235

Closed
1 task done
will-af opened this issue Jan 16, 2025 · 0 comments · Fixed by #3258
Closed
1 task done

ContractFunctionRevertedError does not expose raw revert data #3235

will-af opened this issue Jan 16, 2025 · 0 comments · Fixed by #3258
Labels
Good First Issue Misc: Good First Issue

Comments

@will-af
Copy link
Contributor

will-af commented Jan 16, 2025

Check existing issues

Viem Version

viem@2.22.9

Current Behavior

Calls to contract functions that revert do not make the revert data of the error available to the caller of readContract, writeContract, simulateContract, and other viem functions that ultimately invoke contract functions.

All of the functions mentioned above call getContractError, which ultimately creates a new ContractFunctionRevertedError. That constructor tries to decode the error and sets it to the data field if successful, but decodeErrorResult can and does throw (e.g. if the ABI function is not found), which causes the data field to be undefined, meaning the error is not parsed and the revert data is not exposed.

It is reasonable that a user may like to do their own error decoding, especially since viem cannot decode errors from contracts called by the entrypoint contract (see #1198), but the user is not able to do so because they lack the full revert data and only have the error signature.

Expected Behavior

ContractFunctionRevertError should expose the raw revert data if it was provided to it, allowing upstream callers of readContract, writeContract, simulateContract, and other functions that may throw this error to properly parse errors themselves.

Steps To Reproduce

Run tsx ./index.ts in the linked Minimum Reproducible Example.

  1. Configure a viem project pointing to sepolia testnet such that you can call simulateContract according to the docs.
  2. Call simulateContract doing a call that will fail without including errors in the provided ABI (this could be how the caller configures it, but it also simulates the revert happening in some downstream contract from the one with the provided ABI)
  3. Observe that the full revert data is not exposed in the caught error or in any recursive call to error.cause

Link to Minimal Reproducible Example

https://stackblitz.com/edit/viem-getting-started-qsjdqf9v?file=index.ts

Anything else?

No response

@jxom jxom added the Good First Issue Misc: Good First Issue label Jan 21, 2025
will-af added a commit to will-af/viem that referenced this issue Jan 22, 2025
Exposes otherwise missing raw revert data via a new rawData field
on the ContractFunctionRevertedError

Fixes wevm#3235
will-af added a commit to will-af/viem that referenced this issue Jan 22, 2025
Exposes otherwise missing raw revert data via a new rawData field
on the ContractFunctionRevertedError

Fixes wevm#3235
will-af added a commit to will-af/viem that referenced this issue Jan 22, 2025
Exposes otherwise missing raw revert data via a new rawData field
on the ContractFunctionRevertedError

Fixes wevm#3235
@jxom jxom closed this as completed in f32fc92 Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Misc: Good First Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants