Skip to content

Commit 9252e98

Browse files
authored
chore: format chained error for EvmError (#9169)
1 parent 4d7435e commit 9252e98

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

crates/evm/evm/src/executors/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ pub enum EvmError {
663663
Skip(SkipReason),
664664
/// Any other error.
665665
#[error(transparent)]
666-
Eyre(#[from] eyre::Error),
666+
Eyre(eyre::Error),
667667
}
668668

669669
impl From<ExecutionErr> for EvmError {
@@ -678,6 +678,16 @@ impl From<alloy_sol_types::Error> for EvmError {
678678
}
679679
}
680680

681+
impl From<eyre::Error> for EvmError {
682+
fn from(err: eyre::Report) -> Self {
683+
let mut chained_cause = String::new();
684+
for cause in err.chain() {
685+
chained_cause.push_str(format!("{cause}; ").as_str());
686+
}
687+
Self::Eyre(eyre::format_err!("{chained_cause}"))
688+
}
689+
}
690+
681691
/// The result of a deployment.
682692
#[derive(Debug)]
683693
pub struct DeployResult {

crates/forge/tests/cli/script.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,3 +2210,27 @@ Simulated On-chain Traces:
22102210
...
22112211
"#]]);
22122212
});
2213+
2214+
// Tests that chained errors are properly displayed.
2215+
// <https://github.com/foundry-rs/foundry/issues/9161>
2216+
forgetest_init!(should_display_evm_chained_error, |prj, cmd| {
2217+
let script = prj
2218+
.add_source(
2219+
"Foo",
2220+
r#"
2221+
import "forge-std/Script.sol";
2222+
2223+
contract ContractScript is Script {
2224+
function run() public {
2225+
}
2226+
}
2227+
"#,
2228+
)
2229+
.unwrap();
2230+
cmd.arg("script").arg(script).args(["--fork-url", "https://public-node.testnet.rsk.co"]).assert_failure().stderr_eq(str![[r#"
2231+
Error:
2232+
Failed to deploy script:
2233+
backend: failed while inspecting; header validation error: `prevrandao` not set; `prevrandao` not set;
2234+
2235+
"#]]);
2236+
});

0 commit comments

Comments
 (0)