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

fix(cast): try decoding custom errors when execution reverted in cast send #9794

Merged
merged 5 commits into from
Feb 4, 2025

Conversation

grandizzy
Copy link
Collaborator

@grandizzy grandizzy commented Jan 31, 2025

Motivation

Solution

  • try decode custom error with SignaturesIdentifier if code 3 and append to output e.g.
Error: server returned an error response: error code 3: execution reverted: custom error 0x6786ad34: ..., data: "...": AddressInsufficientBalance(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, 1000)

@grandizzy grandizzy added T-bug Type: bug C-cast Command: cast labels Jan 31, 2025
@grandizzy grandizzy marked this pull request as ready for review January 31, 2025 09:24
@grandizzy grandizzy marked this pull request as draft January 31, 2025 21:04
@grandizzy grandizzy marked this pull request as ready for review February 3, 2025 07:39
@grandizzy grandizzy requested a review from DaniPopes February 3, 2025 07:39
@grandizzy grandizzy changed the title fix(cast): try decoding custom errors when execution reverted in cast fix(cast): try decoding custom errors when execution reverted in cast send Feb 4, 2025

/// Helper function that tries to decode custom error name and inputs from error payload data.
async fn decode_execution_revert(data: &RawValue) -> Result<Option<String>> {
if let Some(err_data) = data.to_string().replace("\"", "").strip_prefix("0x") {
Copy link
Member

Choose a reason for hiding this comment

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

serde_json::from_value::<String is probably better

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to using serde_json::from_str::<String> in e9b5e66

let mut decoded_error = known_error.name.clone();
if !known_error.inputs.is_empty() {
decoded_error.push('(');
let error = known_error.decode_error(&hex::decode(err_data)?)?;
Copy link
Member

Choose a reason for hiding this comment

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

you should be able to do write!("({})", ...) with itertools .format(", ")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed in e9b5e66

@grandizzy grandizzy requested a review from DaniPopes February 4, 2025 09:13
Ok(())
}
Err(err) => {
if let TransportError::ErrorResp(ref payload) = err {
Copy link
Member

Choose a reason for hiding this comment

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

please use & not ref

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops, fixed

@grandizzy grandizzy enabled auto-merge (squash) February 4, 2025 13:09
@grandizzy grandizzy merged commit be5e714 into foundry-rs:master Feb 4, 2025
22 checks passed
@frolic
Copy link

frolic commented Feb 4, 2025

amazingggg, thank you!

@grandizzy grandizzy deleted the issue-9789 branch February 4, 2025 13:55
@grandizzy grandizzy self-assigned this Feb 10, 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-bug Type: bug
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(cast): parse custom errors from cast send with local artifacts
5 participants