foundry
foundry copied to clipboard
bug(`cast`): `cast send` doesn't display custom errors on tx reverts
Component
Cast
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] 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;
}
}
- Run Anvil
-
forge create SimpleStorage --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
-
cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setValue(uint256)" 101 --private-key=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80