Skip to content

Commit

Permalink
replace console_error_panic_hook with throwing the panic
Browse files Browse the repository at this point in the history
  • Loading branch information
rniii committed Jan 9, 2024
1 parent 06bf928 commit 8bb808f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ tracy-client = { version = "0.16", optional = true }
android_log-sys = "0.3.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.6"
tracing-wasm = "0.2.1"
wasm-bindgen = "0.2.89"

[lints]
workspace = true
10 changes: 8 additions & 2 deletions crates/bevy_log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
mod once;

#[cfg(feature = "trace")]
#[cfg(any(feature = "trace", target_arch = "wasm32"))]
use std::panic;

#[cfg(target_os = "android")]
Expand Down Expand Up @@ -184,7 +184,13 @@ impl Plugin for LogPlugin {

#[cfg(target_arch = "wasm32")]
{
console_error_panic_hook::set_once();
use wasm_bindgen::{throw_val, JsError};

let old_handler = panic::take_hook();
panic::set_hook(Box::new(move |info| {
throw_val(JsError::new(&info.to_string()).into())
}));

finished_subscriber = subscriber.with(tracing_wasm::WASMLayer::new(
tracing_wasm::WASMLayerConfig::default(),
));
Expand Down

0 comments on commit 8bb808f

Please sign in to comment.