serde-error

A (de)serializable Rust Error type that captures the full causality chain for sending over the wire.

Library
Cargo
v0.1.3
5stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
17/100Needs Attention
Development Activity0
Maintenance0
Community8
Maturity60
Momentum0

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture72
Code Quality74
Innovation70
Learning Curve88

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::Error type that derives serde::Serialize and serde::Deserialize.
  • Error::new(&e) to snapshot any std::error::Error and its full source() chain.
  • Implementations of std::error::Error, Display, and Debug so the type behaves like a native error.
  • Round-trip conversion back into anyhow::Error for 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search