Skip to main content

Module panic_hook

Module panic_hook 

Source
Expand description

The wasm panic hook every #[wasm_bindgen] entry point installs. Replaces the console_error_panic_hook crate for the whole BREP family — reached as brep_kernel::panic_hook and, through the render engine’s re-export, as brep_render::brep_kernel::panic_hook. The wasm panic hook: a Rust panic reaches the browser console instead of the bare RuntimeError: unreachable wasm traps produce by default.

[set_once] is what every wasm entry point in the family calls first — the kernel’s #[wasm_bindgen] ABI, brep_render::Engine::new, the app’s start and its history worker. It replaces the console_error_panic_hook crate, whose whole content this is; the kernel already links wasm-bindgen, so owning it costs nothing and drops a dependency from three crates.

On every non-wasm target it is a no-op, deliberately — and that is a change from the crate it replaces. console_error_panic_hook::set_once() installed a native hook too, one that printed the panic message alone; because the ABI functions that call it also run in native tests and in BREP_mcp’s headless host, the first ABI call there quietly cost every later panic its backtrace and the RUST_BACKTRACE hint. Doing nothing leaves the standard hook in place, which prints both.

Functions§

set_once
Install the panic hook, at most once per module instance. Cheap enough to call from every entry point, which is how it is used.