From 002c086b8daad0baf577c09e58399c2e3f29759c Mon Sep 17 00:00:00 2001 From: BowTiedWoo Date: Wed, 13 Nov 2024 22:07:05 +0200 Subject: [PATCH] fix: error handling in `crosscheck_compare_only` --- clar2wasm/src/tools.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/clar2wasm/src/tools.rs b/clar2wasm/src/tools.rs index cf1577b6..b1ac221d 100644 --- a/clar2wasm/src/tools.rs +++ b/clar2wasm/src/tools.rs @@ -533,9 +533,26 @@ pub fn crosscheck_compare_only(snippet: &str) { TestEnvironment::new(TestConfig::latest_epoch(), TestConfig::clarity_version()), snippet, |result| { - // Note that we interpret first, to catch logical errors early - assert!(result.interpreted.is_ok(), "Interpreted snippet failed"); - assert!(result.compiled.is_ok(), "Compiled snippet failed"); + // If both interpreted and compiled results have errors, panic and + // show both errors. + // If only one fails, panic with the error from the failing one. + match (result.interpreted.as_ref(), result.compiled.as_ref()) { + (Err(interpreted_err), Err(compiled_err)) => { + panic!( + "Interpreted and compiled snippets failed: {:?}, {:?}", + interpreted_err, compiled_err + ); + } + (Err(interpreted_err), Ok(_)) => { + panic!("Interpreted snippet failed: {:?}", interpreted_err); + } + (Ok(_), Err(compiled_err)) => { + panic!("Compiled snippet failed: {:?}", compiled_err); + } + _ => { + // Both succeeded; no action needed. + } + } }, ); }