You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This crate lets you debug panics on wasm32-unknown-unknown by providing a
panic hook that forwards panic messages to
console.error.
When an error is reported with console.error, browser devtools and node.js
will typically capture a stack trace and display it with the logged error
message.
Without console_error_panic_hook you just get something like RuntimeError: Unreachable executed
Browser:
Node:
With this panic hook installed you will see the panic message
Browser:
Node:
Usage
There are two ways to install this panic hook.
First, you can set the hook yourself by calling std::panic::set_hook in
some initialization function:
Alternatively, use set_once on some common code path to ensure that
set_hook is called, but only the one time. Under the hood, this uses
std::sync::Once.
Many browsers only capture the top 10 frames of a stack trace. In rust programs this is less likely to be enough. To see more frames, you can set the non-standard value Error.stackTraceLimit. For more information see the MDN Web Docs or v8 docs.
About
A panic hook for wasm32-unknown-unknown that logs panics with console.error