Skip to content

Preserve error cause in getContractError#4388

Merged
jxom merged 4 commits intowevm:mainfrom
alcuadrado:preserve-error-cause-in-getContractError
Mar 17, 2026
Merged

Preserve error cause in getContractError#4388
jxom merged 4 commits intowevm:mainfrom
alcuadrado:preserve-error-cause-in-getContractError

Conversation

@alcuadrado
Copy link
Copy Markdown
Contributor

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.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 9, 2026

@alcuadrado is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 9, 2026

🦋 Changeset detected

Latest commit: 2cd5152

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

This PR includes changesets to release 1 package
Name Type
viem 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

@alcuadrado alcuadrado changed the title Preserve error cause in get contract error Preserve error cause in getContractError Mar 9, 2026
}
export class AbiDecodingZeroDataError extends BaseError {
constructor() {
constructor({ cause }: { cause?: BaseError | Error | undefined } = {}) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The changes in this file are present because I made decodeErrorResult preserve the error cause in most cases.

data,
functionName,
message,
cause: error,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to rename cause, which is used below, to keep the PR minimal. Let me know if you prefer something else.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

npm i https://pkg.pr.new/viem@4388

commit: 98be1e6

: `The contract function "${functionName}" reverted.`,
{
cause,
cause: cause ?? error,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@jxom jxom merged commit 60f701f into wevm:main Mar 17, 2026
14 of 28 checks passed
@github-actions github-actions bot mentioned this pull request Mar 17, 2026
@tmm tmm mentioned this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getContractError can loose the error cause when a custom provider is used

2 participants