rustwasm / console_error_panic_hook

A panic hook for wasm32-unknown-unknown that logs panics with console.error
Apache License 2.0
320 stars 24 forks source link

Setting panic hook in initialization function causes wasm-pack to break #26

Open ThatNerdUKnow opened 1 year ago

ThatNerdUKnow commented 1 year ago

Describe the Bug

I'm defining my initalization function like so:

#[wasm_bindgen]
pub fn init() {
    #[cfg(feature = "console_error_panic_hook")]
    panic::set_hook(Box::new(console_error_panic_hook::hook));

    //set_panic_hook();
    wasm_logger::init(wasm_logger::Config::default());
}

This gives the following error when running wasm-pack build --release

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"Error"`,
 right: `"Error2"`', crates\cli-support\src\js\mod.rs:175:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 101
  full command: "C:\\Users\\brand\\AppData\\Local\\.wasm-pack\\wasm-bindgen-7e757a9923d43b8a\\wasm-bindgen.exe" "C:\\Users\\brand\\repos\\celeste\\satellite-rs\\target\\wasm32-unknown-unknown\\release\\satellite_rs.wasm" "--out-dir" "C:\\Users\\brand\\repos\\celeste\\satellite-rs\\pkg" "--typescript" "--target" "bundler"

this error does not occur if I disable the "console_error_panic_hook" feature

Steps to Reproduce

  1. See error

Expected Behavior

I would expect that I would be able to create a wasm-bindgen function that I can call from my frontend to initalize the logging hook

Actual Behavior

Got the following error on wasm-pack build:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"Error"`,
 right: `"Error2"`', crates\cli-support\src\js\mod.rs:175:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: Running the wasm-bindgen CLI
Caused by: Running the wasm-bindgen CLI
Caused by: failed to execute `wasm-bindgen`: exited with exit code: 101
  full command: "C:\\Users\\brand\\AppData\\Local\\.wasm-pack\\wasm-bindgen-7e757a9923d43b8a\\wasm-bindgen.exe" "C:\\Users\\brand\\repos\\celeste\\satellite-rs\\target\\wasm32-unknown-unknown\\release\\satellite_rs.wasm" "--out-dir" "C:\\Users\\brand\\repos\\celeste\\satellite-rs\\pkg" "--typescript" "--target" "bundler"