From 8f8bd40e8d870028ba299bf124ed45530da50954 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 12 Jul 2022 10:15:25 +0200 Subject: [PATCH] feat(bindings/crypto-js): Redirect Rust panics to JavaScript console. --- bindings/matrix-sdk-crypto-js/Cargo.toml | 1 + bindings/matrix-sdk-crypto-js/src/lib.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/bindings/matrix-sdk-crypto-js/Cargo.toml b/bindings/matrix-sdk-crypto-js/Cargo.toml index 94d14468c..b5cbe56af 100644 --- a/bindings/matrix-sdk-crypto-js/Cargo.toml +++ b/bindings/matrix-sdk-crypto-js/Cargo.toml @@ -34,6 +34,7 @@ vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7 wasm-bindgen = "0.2.80" wasm-bindgen-futures = "0.4.30" js-sys = "0.3.49" +console_error_panic_hook = "0.1.7" serde_json = "1.0.79" http = "0.2.6" anyhow = "1.0" diff --git a/bindings/matrix-sdk-crypto-js/src/lib.rs b/bindings/matrix-sdk-crypto-js/src/lib.rs index a9b59426f..a985e4138 100644 --- a/bindings/matrix-sdk-crypto-js/src/lib.rs +++ b/bindings/matrix-sdk-crypto-js/src/lib.rs @@ -29,6 +29,16 @@ pub mod sync_events; use js_sys::{Object, Reflect}; use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*}; +/// Run some stuff when the Wasm module is instantiated. +/// +/// Right now, it does the following: +/// +/// * Redirect Rust panics to JavaScript console. +#[wasm_bindgen(start)] +pub fn start() { + console_error_panic_hook::set_once(); +} + /// A really hacky and dirty code to downcast a `JsValue` to `T: /// RefFromWasmAbi`, inspired by /// https://github.com/rustwasm/wasm-bindgen/issues/2231#issuecomment-656293288.