#[cfg(target_arch = "wasm32")]
mod imp {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn error(msg: String);
type Error;
#[wasm_bindgen(constructor)]
fn new() -> Error;
#[wasm_bindgen(structural, method, getter)]
fn stack(error: &Error) -> String;
}
fn hook(info: &std::panic::PanicHookInfo<'_>) {
let mut msg = info.to_string();
msg.push_str("\n\nStack:\n\n");
msg.push_str(&Error::new().stack());
msg.push_str("\n\n");
error(msg);
}
pub fn set_once() {
use std::sync::Once;
static SET: Once = Once::new();
SET.call_once(|| std::panic::set_hook(Box::new(hook)));
}
}
#[cfg(not(target_arch = "wasm32"))]
mod imp {
pub fn set_once() {}
}
pub fn set_once() {
imp::set_once();
}