diff --git a/Cargo.lock b/Cargo.lock index 4733bb4f7..1ac3fd142 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -877,6 +877,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "const-oid" version = "0.9.6" @@ -3094,6 +3104,7 @@ dependencies = [ "anyhow", "as_variant", "async-compat", + "console_error_panic_hook", "extension-trait", "eyeball-im", "futures-util", diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 117a1204b..c36bb2cd9 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -80,6 +80,7 @@ uuid = { version = "1.4.1", features = ["v4"] } zeroize.workspace = true [target.'cfg(target_family = "wasm")'.dependencies] +console_error_panic_hook = "0.1.7" tokio = { workspace = true, features = ["sync", "macros"] } uniffi.workspace = true diff --git a/bindings/matrix-sdk-ffi/src/platform.rs b/bindings/matrix-sdk-ffi/src/platform.rs index d80db1627..6ff4be1a4 100644 --- a/bindings/matrix-sdk-ffi/src/platform.rs +++ b/bindings/matrix-sdk-ffi/src/platform.rs @@ -526,15 +526,22 @@ pub fn init_platform( config: TracingConfiguration, use_lightweight_tokio_runtime: bool, ) -> Result<(), ClientError> { - LOGGING.set(config.build()).map_err(|_| ClientError::Generic { - msg: "logger already initialized".to_owned(), - details: None, - })?; + #[cfg(all(feature = "js", target_family = "wasm"))] + { + console_error_panic_hook::set_once(); + } + #[cfg(not(target_family = "wasm"))] + { + LOGGING.set(config.build()).map_err(|_| ClientError::Generic { + msg: "logger already initialized".to_owned(), + details: None, + })?; - if use_lightweight_tokio_runtime { - setup_lightweight_tokio_runtime(); - } else { - setup_multithreaded_tokio_runtime(); + if use_lightweight_tokio_runtime { + setup_lightweight_tokio_runtime(); + } else { + setup_multithreaded_tokio_runtime(); + } } Ok(()) @@ -557,6 +564,7 @@ pub fn enable_sentry_logging(enabled: bool) { }; } +#[cfg(not(target_family = "wasm"))] fn setup_multithreaded_tokio_runtime() { async_compat::set_runtime_builder(Box::new(|| { eprintln!("spawning a multithreaded tokio runtime"); @@ -567,6 +575,7 @@ fn setup_multithreaded_tokio_runtime() { })); } +#[cfg(not(target_family = "wasm"))] fn setup_lightweight_tokio_runtime() { async_compat::set_runtime_builder(Box::new(|| { eprintln!("spawning a lightweight tokio runtime");