workflow_wasm/
panic.rs

1//!
2//! Handling of WASM panic hook that allows activation of console-based panic hook
3//! as well as a browser-based panic hook.  (the browser-based panic hook activates a full-screen debug
4//! information output in case of a panic - useful on mobile devices or where
5//! the user otherwise has no access to console/developer tools)
6//!
7
8use wasm_bindgen::prelude::*;
9use workflow_panic_hook::{set_once, show_logs as show_wasm_logs, Type};
10
11/// Initialize Rust panic handler in console mode.
12///
13/// This will output additional debug information during a panic to the console.
14/// This function should be called right after loading WASM libraries.
15/// @category General
16#[wasm_bindgen(js_name = "initConsolePanicHook")]
17pub fn init_console_panic_hook() {
18    set_once(Type::Console);
19}
20
21/// Initialize Rust panic handler in browser mode.
22///
23/// This will output additional debug information during a panic in the browser
24/// by creating a full-screen `DIV`. This is useful on mobile devices or where
25/// the user otherwise has no access to console/developer tools. Use
26/// {@link presentPanicHookLogs} to activate the panic logs in the
27/// browser environment.
28/// @see {@link presentPanicHookLogs}
29/// @category General
30#[wasm_bindgen(js_name = "initBrowserPanicHook")]
31pub fn init_browser_panic_hook() {
32    set_once(Type::Popup);
33}
34
35/// Present panic logs to the user in the browser.
36///
37/// This function should be called after a panic has occurred and the
38/// browser-based panic hook has been activated. It will present the
39/// collected panic logs in a full-screen `DIV` in the browser.
40/// @see {@link initBrowserPanicHook}
41/// @category General
42#[wasm_bindgen(js_name = "presentPanicHookLogs")]
43pub fn show_panic_hook_logs() {
44    show_wasm_logs();
45}