From 7967f33ee06ba6e2f537ca51b0cdf29582f009ff Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Wed, 11 Dec 2024 16:19:24 -0300 Subject: [PATCH] Handle `panic!("...")` in catch_unwind handling --- tooling/nargo_cli/src/cli/test_cmd.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 488176c531..7ebf222e88 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -185,9 +185,15 @@ impl<'a> TestRunner<'a> { let time_before_test = std::time::Instant::now(); let (status, output) = match catch_unwind(test.runner) { Ok((status, output)) => (status, output), - Err(_) => ( + Err(err) => ( TestStatus::Fail { - message: "An unexpected error happened".to_string(), + message: + // It seems `panic!("...")` makes the error be `&str`, so we handle this common case + if let Some(message) = err.downcast_ref::<&str>() { + message.to_string() + } else { + "An unexpected error happened".to_string() + }, error_diagnostic: None, }, String::new(),