Preserve error cause in getContractError#4388
Conversation
|
@alcuadrado is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 2cd5152 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
getContractError
| } | ||
| export class AbiDecodingZeroDataError extends BaseError { | ||
| constructor() { | ||
| constructor({ cause }: { cause?: BaseError | Error | undefined } = {}) { |
There was a problem hiding this comment.
I added a default param to keep this PR small. If you want, I can take a look at making it required.
| } | ||
|
|
||
| export type AbiDecodingZeroDataErrorType = AbiDecodingZeroDataError & { | ||
| name: 'AbiDecodingZeroDataError' |
There was a problem hiding this comment.
The changes in this file are present because I made decodeErrorResult preserve the error cause in most cases.
| data, | ||
| functionName, | ||
| message, | ||
| cause: error, |
There was a problem hiding this comment.
I didn't want to rename cause, which is used below, to keep the PR minimal. Let me know if you prefer something else.
commit: |
| : `The contract function "${functionName}" reverted.`, | ||
| { | ||
| cause, | ||
| cause: cause ?? error, |
There was a problem hiding this comment.
This change also affected some other errors/test, so I had to update some unrelated snapshots. They now have a details field.
| abiItem, | ||
| args: | ||
| 'inputs' in abiItem && abiItem.inputs && abiItem.inputs.length > 0 | ||
| ? decodeAbiParameters(abiItem.inputs, slice(data, 4)) |
There was a problem hiding this comment.
If decodeAbiParameters throws here, we loose the cause. I left it like this to keep the PR minimal, and added a test that acts as a witness of this limitation. Open to take another approach.
bdf8494 to
69e0d6e
Compare
Fixes #4387
I didn't manage to run the entire test suite in my local machine, sorry in advance if something fails on CI. I'll fix it.
I'll leave some comments for the reviewer in the PR as well.