Stream: wasmtime

Topic: ✔ Custom Trap


view this post on Zulip vnmrd (Sep 18 2023 at 12:59):

Is there any way to implement a custom trap? I used to code Trap::new("custom trap") in the 0.35.1 version.

view this post on Zulip Alex Crichton (Sep 18 2023 at 14:38):

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)

view this post on Zulip vnmrd (Sep 18 2023 at 14:49):

Great, thank you!

view this post on Zulip Notification Bot (Sep 18 2023 at 14:49):

vnmrd has marked this topic as resolved.


Last updated: Oct 23 2024 at 20:03 UTC