Alloc_error when using Web Worker

Using Rust WASM you may run into panics. The suggested crate is to use console_error_panic_hook to see the panic with a helpful backtrace.

Even with using this crate it may continue to panic with RuntimeError: unreachable executed without the backtrace. I spent some time trying to identify the issue but no matter how I set up the crate it would continue with this error.

I broke out the code that was running into a separate wasm-bindgen-test crate test. This allows you to run your WASM tests in the browser. Then ran the associated code in the test. This finally gave me a backtrace in the code with an interesting bug. An alloc_error. Like the following:

RuntimeError: unreachable executed

RuntimeError: unreachable executed
       __rg_oom@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[16002]:0xc646f8
       __rust_alloc_error_handler@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[16228]:0xc65823
       alloc::alloc::handle_alloc_error::rt_error::he3b3ec192280323d@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[16647]:0xc66ae1
       alloc::alloc::handle_alloc_error::h0853c609cdf121f4@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[16646]:0xc66ad5
       alloc::raw_vec::handle_reserve::h299111c3271c7313@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[5569]:0xb6aace
       alloc::raw_vec::RawVec<T,A>::reserve_for_push::h99a1d9f2e43adc2f@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[10283]:0xc0ffd9
       alloc::vec::Vec<T,A>::push::ha6011ff2e9fdf3e0@http://localhost:8000/wasm-bindgen-test_bg.wasm:wasm-function[4708]:0xb36243

This generally is the error that happens when you run out of memory. You could fix it to handle running out of memory better. But a better solution is to figure out how to reduce the amount of memory that is being used. I couldn’t find exact memory usage limits for the browser but from 40 MB to around 190 MB possibly. You could test the limits on your browsers to get a better idea.

Hopefully that was helpful to identify other things that may prevent the console_error_panic_hook from presenting and how to view errors using wasm-bindgen-test.