Let's say various components implement their own error type with thiserror, and they execute their component via wasmtime.
Is there a good way to express this in WIT such that the host can attempt to downcast it into the original error type?
In other words - passing the full error from the component, as a general anyhow::Error?
I'm going to assume you're talking about a Rust guest w/ a Rust host since that's implied, but note that other languages obviously don't have thiserror.
The "original" error type just doesn't exist on the side of the host -- are you implying that the guest and host share a common library or some common definitions for the given error?
Starting somewhat from a higher level, variants are generally how errors can be represented that is most similar to the Rust enum + thiserror model -- so if you can create From<WitVariantErrorType> instances for your RustError type (on both sides, or in a shared library that both sides can share), you can build the Rusty error you want from the generated enum (i.e. what wit-bindgen will generate) and convert back and forth.
It is possible to include bindgen output (along with extra implementation and other helper functions/types) in a shared library and distribute that to either side. Somewhat obvious but spelling it out -- when the WIT changes, you change the shared lib crate and update the helpers then update both sides.
There may be more interesting ways to integrate/tie the generated enum for the error variant, and your your error class (w/ thiserror) together, but a From implementation is the basic way that is sure to work though a bit of boilerplate.
thanks for the feedback!
The "original" error type just doesn't exist on the side of the host
Right, my question assumes that the host (or other code it calls) can downcast from anyhow::Error into a specific type that it knows about.
though I guess what I'm asking boils down to serializing anyhow::Error, which has its own issues independent of wasm... and so I might as well just serialize the original error type into JSON or bincode or whatever and then the host can try to deserialize that
Last updated: Dec 06 2025 at 05:03 UTC