You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I checked there isn't already an issue for the bug I encountered.
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.
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.
Configure a viem project pointing to sepolia testnet such that you can call simulateContractaccording to the docs.
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)
Observe that the full revert data is not exposed in the caught error or in any recursive call to error.cause
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 ofreadContract
,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.simulateContract
according to the docs.error.cause
Link to Minimal Reproducible Example
https://stackblitz.com/edit/viem-getting-started-qsjdqf9v?file=index.ts
Anything else?
No response
The text was updated successfully, but these errors were encountered: