From 805aaa2273d02bf5248a33da997777f6510706a8 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 16 Apr 2019 11:50:08 -0700 Subject: [PATCH] Log stacks of imported JS functions that throw but are not marked `catch` Particularly useful in our tests, where we don't have the regular console logging with post-facto object inspection, and instead need to provide all this info up front. --- crates/cli-support/src/js/rust2js.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/cli-support/src/js/rust2js.rs b/crates/cli-support/src/js/rust2js.rs index c0d5b55e..50eb8d37 100644 --- a/crates/cli-support/src/js/rust2js.rs +++ b/crates/cli-support/src/js/rust2js.rs @@ -716,13 +716,23 @@ impl<'a, 'b> Rust2Js<'a, 'b> { try {{\n\ {} }} catch (e) {{\n\ - console.error(\"wasm-bindgen: imported JS function that \ + let error = (function () {{ + try {{ + return e instanceof Error + ? `${{e.message}}\n\nStack:\n${{e.stack}}` + : e.toString(); + }} catch(_) {{ + return \"\"; + }} + }}()); + console.error(\"wasm-bindgen: imported JS function `{}` that \ was not marked as `catch` threw an error:\", \ - e); + error); throw e; }}\ ", &invoc, + shim, ); }