I want to get the panic message from a guest in for example a call to panic!("I failed because X")
.
From this issue: https://github.com/bytecodealliance/wasmtime/issues/4054 it sounds like this might not be possible but I wanted to check whether there's been any developments here. Thanks!
I forgot to mention that this is in the context of using wit-bindgen
to generate the guest and compiling for wasm32-unknown-unknown
.
Webassembly doesn't provide a mechanism for the guest to provide the panic message. You can set a custom panic hook in the guest using std::panic::set_hook
and then inside this panic hook call a host function to provide the panic message though.
By the way be aware that wasm32-unknown-unknown doesn't use the correct C abi that wasm32-wasi and wasm32-unknown-emscripten use. A mistake was made when initially adding webassembly support to rustc and we can't change it anymore was wasm-bindgen depends on the broken abi. I'm not sure if wit-bindgen works correctly with the broken abi.
Thanks this set_hook
worked for me. So far wit-bindgen
is working great. Would be interested to know about this problem if you have any links?
Lloyd Fournier has marked this topic as resolved.
Last updated: Dec 23 2024 at 13:07 UTC