Is there any way to implement a custom trap? I used to code Trap::new("custom trap") in the 0.35.1 version.
All wasmtime host functions are allowed to return anyhow::Result<()> and any error will be interpreted as a trap for wasm. The Trap enum is used to model wasm-specific traps, but your own errors can be converted to anyhow::Error which will show up as traps as well. For what you did in 0.35.1 you should be able to use anyhow::bail!("custom trap") for equivalent functionality (or anyhow::anyhow!("custom trap") to create an anyhow::Error object)
Great, thank you!
vnmrd has marked this topic as resolved.
Last updated: Dec 06 2025 at 06:05 UTC