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

bug(cast): cast send/run doesn't display custom errors on tx reverts #8606

Closed
2 tasks done
rplusq opened this issue Aug 5, 2024 · 3 comments
Closed
2 tasks done

bug(cast): cast send/run doesn't display custom errors on tx reverts #8606

rplusq opened this issue Aug 5, 2024 · 3 comments
Labels
C-cast Command: cast P-normal Priority: normal T-bug Type: bug
Milestone

Comments

@rplusq
Copy link
Contributor

rplusq commented Aug 5, 2024

Component

Cast

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (0b73b42 2024-08-05T00:19:50.130854000Z)

What command(s) is the bug in?

anvil; forge create SimpleStorage --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80; cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setValue(uint256)" 101 --private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Operating System

macOS (Apple Silicon)

Describe the bug

When running cast send, if your tx reverts with a custom error, cast only displays:

Error: 
server returned an error response: error code 3: execution reverted: 

But no custom error (nor error, nor signature), which makes it super hard to debug.

Reproducible with the anvil's default private key with this contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 private storedValue;

    event ValueChanged(uint256 newValue);

    error ValueTooHigh(uint256 providedValue, uint256 maxValue);

    function setValue(uint256 _newValue) public {
        if (_newValue > 100) {
            revert ValueTooHigh({ providedValue: _newValue, maxValue: 100 });
        }
        storedValue = _newValue;
        emit ValueChanged(_newValue);
    }

    function getValue() public view returns (uint256) {
        return storedValue;
    }

    function incrementValue() public {
        storedValue += 1;
        emit ValueChanged(storedValue);
    }

    function divideTenBy(uint256 _divisor) public pure returns (uint256) {
        require(_divisor != 0, "Cannot divide by zero");
        return 10 / _divisor;
    }
}
  1. Run Anvil
  2. forge create SimpleStorage --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
  3. cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setValue(uint256)" 101 --private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
@rplusq rplusq added the T-bug Type: bug label Aug 5, 2024
@rplusq
Copy link
Contributor Author

rplusq commented Aug 5, 2024

Interested in solving this one

@cuiweixie
Copy link
Contributor

see #8603

@zerosnacks zerosnacks changed the title bug: cast send doesn't display custom errors on tx reverts bug(cast): cast send doesn't display custom errors on tx reverts Aug 6, 2024
@zerosnacks zerosnacks added the C-cast Command: cast label Aug 6, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Aug 6, 2024
@grandizzy grandizzy changed the title bug(cast): cast send doesn't display custom errors on tx reverts bug(cast): cast send/run doesn't display custom errors on tx reverts Nov 14, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 14, 2024
@grandizzy grandizzy added the P-normal Priority: normal label Nov 14, 2024
@grandizzy
Copy link
Collaborator

this is fixed now, showing

server returned an error response: error code 3: execution reverted: custom error 0x7a0e1985: ed, data: "0x7a0e198500000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000000064

to see decode with project abis, then you can use
forge selectors find 0x7a0e1985

which will return

+-------+-------------------------------+------------+---------------+
| Type  | Signature                     | Selector   | Contract      |
+====================================================================+
| Error | ValueTooHigh(uint256,uint256) | 0x7a0e1985 | SimpleStorage |
+-------+-------------------------------+------------+---------------+

Please reopen if still an issue for you. thank you!

@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast P-normal Priority: normal T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants