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

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.