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

feat(cast): parse custom errors from cast send with local artifacts #9789

Open
holic opened this issue Jan 30, 2025 · 5 comments · May be fixed by #9794
Open

feat(cast): parse custom errors from cast send with local artifacts #9789

holic opened this issue Jan 30, 2025 · 5 comments · May be fixed by #9794
Labels
C-cast Command: cast T-feature Type: feature

Comments

@holic
Copy link

holic commented Jan 30, 2025

Component

Cast

Describe the feature you would like

I noticed cast call and cast run can now be run with local artifacts (#7359)

Is it possible to do the same thing for cast send? Right now I get a response like

Error: server returned an error response: error code 3: execution reverted: custom error 0xfdde54e2: 223429fa00000000000000000000000000000000000000000000000000000000, data: "0xfdde54e2223429fa00000000000000000000000000000000000000000000000000000000"

It'd be great if the custom error could be parsed via my local artifacts (which does have this selector).

Additional context

No response

@holic holic added T-feature Type: feature T-needs-triage Type: this issue needs to be labelled labels Jan 30, 2025
@github-project-automation github-project-automation bot moved this to Todo in Foundry Jan 30, 2025
@grandizzy
Copy link
Collaborator

hey @holic there's now the cast decode-error you could use to decode such, you can try suggestion here #8860 (comment)

@holic
Copy link
Author

holic commented Jan 30, 2025

Great to know! Any reason this can't be done automatically?

@grandizzy
Copy link
Collaborator

for run and call we're simulating tx and decode from traces, what you see in cast send above is the response from provider (anvil) when trying to estimate tx gas (if you set your gas limit e.g. --gas-limit 1111111 you'll get a receipt for failed tx)
We could probably improve here

if self.tx.gas.is_none() {
self.tx.gas = Some(self.provider.estimate_gas(&self.tx).await?);
}

but not sure there's anything standard we could use to parse and decode, @mattsse could you pls chime in? thanks!

@holic
Copy link
Author

holic commented Jan 30, 2025

I dug through Viem's error handling code and looks like they look for error code 3 and a message containing execution reverted. Then if they find hex data in the error, they treat it as a custom error and attempt to decode the error with the provided ABI, otherwise they fallback to message:
https://github.com/wevm/viem/blob/c2f85790e9f7e55214bf46bc302bf55ba1a43a6b/src/errors/request.ts#L87
https://github.com/wevm/viem/blob/c2f85790e9f7e55214bf46bc302bf55ba1a43a6b/src/utils/errors/getContractError.ts#L67
https://github.com/wevm/viem/blob/c2f85790e9f7e55214bf46bc302bf55ba1a43a6b/src/errors/contract.ts#L194

They also link out to all the eth node sources of errors: https://github.com/wevm/viem/blob/c2f85790e9f7e55214bf46bc302bf55ba1a43a6b/src/errors/node.ts#L5-L13
(Though these links seem outdated now)

@grandizzy
Copy link
Collaborator

awesome info, should do it

@grandizzy grandizzy added C-cast Command: cast and removed T-needs-triage Type: this issue needs to be labelled labels Jan 30, 2025
@grandizzy grandizzy changed the title parse custom errors from cast send with local artifacts feat(cas): parse custom errors from cast send with local artifacts Jan 30, 2025
@holic holic changed the title feat(cas): parse custom errors from cast send with local artifacts feat(cast): parse custom errors from cast send with local artifacts Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-feature Type: feature
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants