serde-error
A (de)serializable Rust Error type that captures the full causality chain for sending over the wire.
Repository Health
Technical Analysis
serde-error is a small Rust crate that provides a serializable and deserializable Error type implementing std::error::Error. By recursively walking an error’s source() chain, it captures the entire causality chain as plain strings, so a rich error can be transmitted across a serialization boundary and reconstructed on the other side.
It was designed for cases where errors must cross a wire or process boundary while preserving their cause hierarchy, such as running Rust WebAssembly blobs inside a wasmtime host. It integrates cleanly with Serde and with anyhow, letting you convert a boxed error into a serializable form and back into an anyhow::Error.
What You Get
- A
serde_error::Errortype that derivesserde::Serializeandserde::Deserialize. Error::new(&e)to snapshot anystd::error::Errorand its fullsource()chain.- Implementations of
std::error::Error,Display, andDebugso the type behaves like a native error. - Round-trip conversion back into
anyhow::Errorfor ergonomic use with the anyhow ecosystem. - A dependency-light crate (only
serde) suitable for constrained targets like WebAssembly.
Common Use Cases
- Transmitting errors from a Rust WebAssembly guest to a wasmtime host with the cause chain intact.
- Sending structured errors across RPC or process boundaries where the full causality matters.
- Persisting or logging an error’s complete source chain in a serialized format.
Under The Hood
Architecture - The entire crate is a single src/lib.rs defining an Error struct with a description: String and an optional boxed source: Option<Box<Error>>. Error::new recursively walks the input error’s source() chain, stringifying each level, which builds a serializable linked list mirroring the original causality chain. Trait impls for std::error::Error, Display, and Debug make the reconstructed value behave like a normal error.
Tech Stack - Pure Rust (2018 edition) with a single runtime dependency on serde (derive feature). Dev-dependencies anyhow and bincode demonstrate real-world round-tripping. The crate is categorized under development-tools/debugging on crates.io.
Code Quality - The implementation is tiny (~44 lines) and idiomatic, using recursion and boxing to model the chain. There is no dedicated test module in src, though the README example serves as documentation and the crate is described as production-grade; its narrow scope keeps correctness easy to verify by inspection.
API Design - The API is minimal and ergonomic: a single Error::new(&e) constructor plus standard trait impls mean adoption requires almost no learning. Conversion to anyhow::Error via From lets it slot into existing anyhow-based error handling with a one-line change.