Skip to content

Commit

Permalink
Log stacks of imported JS functions that throw but are not marked `ca…
Browse files Browse the repository at this point in the history
…tch`

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.
  • Loading branch information
fitzgen committed Apr 17, 2019
1 parent 10cbc78 commit 805aaa2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/cli-support/src/js/rust2js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"<failed to stringify thrown value>\";
}}
}}());
console.error(\"wasm-bindgen: imported JS function `{}` that \
was not marked as `catch` threw an error:\", \
e);
error);
throw e;
}}\
",
&invoc,
shim,
);
}

Expand Down

0 comments on commit 805aaa2

Please sign in to comment.