diff --git a/crates/backend/src/codegen/fn.rs b/crates/backend/src/codegen/fn.rs index 7ccff0ddcf..c724b8d94f 100644 --- a/crates/backend/src/codegen/fn.rs +++ b/crates/backend/src/codegen/fn.rs @@ -140,7 +140,18 @@ impl TryToTokens for NapiFn { quote! { { std::panic::catch_unwind(|| { #function_call }) - .map_err(|e| napi::Error::new(napi::Status::GenericFailure, format!("{:?}", e))) + .map_err(|e| { + let message = { + if let Some(string) = e.downcast_ref::() { + string.clone() + } else if let Some(string) = e.downcast_ref::<&str>() { + string.to_string() + } else { + format!("panic from Rust code: {:?}", e) + } + }; + napi::Error::new(napi::Status::GenericFailure, message) + }) .and_then(|r| r) } }