Open seanvoss opened 5 years ago
I'm not sure if there's a generic solution, but I just write my own:
fn set_panic_hook() {
std::panic::set_hook(Box::new(|info| {
stdweb::print_error_panic(&info.to_string());
}));
}
Now you can call it in main
, like this:
fn main() {
set_panic_hook();
// Rest of code...
}
https://github.com/rustwasm/console_error_panic_hook/blob/master/src/lib.rs
These guys have an implementation that can get you a full stack trace, but it's for wasm-bindgen. You can, however, copy the relevant stack trace code (it's quite small) into the handler Pauan provides.
@cedric-h That crate is equivalent to my code, since print_error_panic
does display the stack trace.
However, console_error_panic_hook
does add in some workarounds for browser bugs. It would be quite easy to port that into print_error_panic
.
Am I going crazy, or was print_error_panic
removed? I can't find it, or an equivalent, anywhere.
@JackMordaunt It's defined in stdweb: https://github.com/koute/stdweb/blob/4d337ee9a0a4542ea5803b46b5124d9bc166dcb7/src/webcore/promise_future.rs#L127
Note that you need to enable both the futures-support
and experimental_features_which_may_break_on_minor_version_bumps
features.
Thanks a lot!
@Pauan Hi, I've been trying to use the print_error_panic. I can't figure out how to enable the
futures-support and experimental_features_which_may_break_on_minor_version_bumps features.
When I try to just use stdweb::print_error_panic(...), the error is
cannot find function
print_error_panic
in cratestdweb
How can I enable the features to get the stack trace for panics? Thank you in advance.
The error output of
Is super difficult to debug. I know there's a panic hook in other implementations of wasm. Is there currently or on the roadmap a plan to add a hook to prettify this?