diff --git a/Cargo.toml b/Cargo.toml index 47a00165152be5e1990c82ed3825a9182be649e3..e67db2e40d5a01e4a79b4e0f1c9939cc6ef7c2b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [features] -default = ["console_error_panic_hook"] +default = [] [dependencies] wasm-bindgen = "0.2" @@ -22,13 +22,7 @@ bincode = "1.2.1" fixedbitset = "0.2.0" ordered-float = { version = "1.0.2", features = ["serde"] } twox-hash = "1.1.1" -web-sys = { version = "0.3.33", features = ["console"] } - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. -console_error_panic_hook = { version = "0.1.1", optional = true } +# web-sys = { version = "0.3.33", features = ["console"] } # `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size # compared to the default allocator's ~10K. It is slower than the default @@ -43,3 +37,4 @@ wasm-bindgen-test = "0.2" [profile.release] opt-level = 3 lto = true +# panic = "abort" diff --git a/pkg/drawing_crdt_bg.wasm b/pkg/drawing_crdt_bg.wasm index 2888f2d143fd698f76bcd1ca8df958fbef434830..c0180fe87e4a7c9d29c9c3e05bd162b246d184fc 100644 Binary files a/pkg/drawing_crdt_bg.wasm and b/pkg/drawing_crdt_bg.wasm differ diff --git a/src/lib.rs b/src/lib.rs index c9f10b11d446d92b5fedc0702c655763c7d0537a..2e4b896f52e103baedd67456415c40754455a776 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,9 @@ #![feature(type_ascription)] +#[cfg(feature = "wee_alloc")] +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + use wasm_bindgen::prelude::*; use js_sys::Error; @@ -10,12 +14,6 @@ use std::ops::Deref; use std::option::Option; use vec_map::VecMap; -#[cfg(feature = "wee_alloc")] -#[global_allocator] -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; - -mod utils; - mod crdt; use crdt::{DeltaVec, EventListener, IntervalUnion, Point, CRDT}; @@ -151,7 +149,20 @@ impl WasmCRDT { pub fn apply_deltas(&mut self, deltas: Box<[u8]>) -> Result<bool, JsValue> { let deltas = match bincode::deserialize(&packing::unpack(&deltas)) { Ok(deltas) => deltas, - Err(error) => return Err(Error::new(&format!("{:?}", error)).into()), + #[allow(unused_variables)] + Err(error) => { + return Err(Error::new({ + #[cfg(debug_assertions)] + { + &format!("{:?}", error) + } + #[cfg(not(debug_assertions))] + { + "apply_deltas deltas deserialise error" + } + }) + .into()) + } }; Ok(self.0.apply_deltas(deltas)) @@ -168,7 +179,20 @@ impl WasmCRDT { ) -> Result<(), JsValue> { let remote_state = match bincode::deserialize(&packing::unpack(&remote_state)) { Ok(remote_state) => remote_state, - Err(error) => return Err(Error::new(&format!("{:?}", error)).into()), + #[allow(unused_variables)] + Err(error) => { + return Err(Error::new({ + #[cfg(debug_assertions)] + { + &format!("{:?}", error) + } + #[cfg(not(debug_assertions))] + { + "fetch_deltas_from_state_vector state deserialise error" + } + }) + .into()) + } }; Ok(self.0.fetch_deltas_from_state_vector(user, &remote_state)) diff --git a/src/utils.rs b/src/utils.rs deleted file mode 100644 index c4be847eed6c3abb7a256df6dbac80fd946d7b86..0000000000000000000000000000000000000000 --- a/src/utils.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[allow(dead_code)] -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 - #[cfg(feature = "console_error_panic_hook")] - console_error_panic_hook::set_once(); -}