Skip to content

Commit 358ee18

Browse files
authored
Merge pull request #1466 from fitzgen/log-stacks
Log stacks of imported JS functions that throw but aren't marked `catch`
2 parents a13eb10 + 805aaa2 commit 358ee18

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/cli-support/src/js/rust2js.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,23 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
716716
try {{\n\
717717
{}
718718
}} catch (e) {{\n\
719-
console.error(\"wasm-bindgen: imported JS function that \
719+
let error = (function () {{
720+
try {{
721+
return e instanceof Error
722+
? `${{e.message}}\n\nStack:\n${{e.stack}}`
723+
: e.toString();
724+
}} catch(_) {{
725+
return \"<failed to stringify thrown value>\";
726+
}}
727+
}}());
728+
console.error(\"wasm-bindgen: imported JS function `{}` that \
720729
was not marked as `catch` threw an error:\", \
721-
e);
730+
error);
722731
throw e;
723732
}}\
724733
",
725734
&invoc,
735+
shim,
726736
);
727737
}
728738

0 commit comments

Comments
 (0)