fixing panic hook weirdness

This commit is contained in:
Jędrzej Stuczyński
2023-12-04 15:08:31 +00:00
parent 3d563ece79
commit aec23a4f83
4 changed files with 19 additions and 1 deletions
+2 -1
View File
@@ -34,7 +34,8 @@ workspace = true
optional = true
[features]
default = ["sleep", "console_error_panic_hook"]
default = ["sleep"]
panic-hook = ["console_error_panic_hook"]
sleep = ["web-sys", "web-sys/Window"]
websocket = [
"getrandom",
+12
View File
@@ -70,3 +70,15 @@ pub async fn sleep(ms: i32) -> Result<(), wasm_bindgen::JsValue> {
js_fut.await?;
Ok(())
}
#[wasm_bindgen]
#[cfg(feature = "panic-hook")]
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
console_error_panic_hook::set_once();
}
+1
View File
@@ -28,6 +28,7 @@ zeroize = { workspace = true }
wasm-utils = { path = "../../common/wasm/utils" }
nym-bin-common = { path = "../../common/bin-common" }
nym-credentials = { path = "../../common/credentials" }
nym-credential-storage = { path = "../../common/credential-storage" }
nym-bandwidth-controller = { path = "../../common/bandwidth-controller" }
+4
View File
@@ -17,6 +17,10 @@ use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
pub fn main() {
wasm_utils::console_log!("[rust main]: rust module loaded");
wasm_utils::console_log!(
"credential client version used: {:#?}",
nym_bin_common::bin_info!()
);
wasm_utils::console_log!("[rust main]: setting panic hook");
wasm_utils::set_panic_hook();
}