rust-error-design
Installation
SKILL.md
Rust error design
Convert ad-hoc error handling to typed errors. The wrong shape leaks through public APIs and infects every caller, so this refactor is usually worth doing early.
Decision tree
Is this code a library / reusable module (has consumers who may need to
match on error variants, retry, or wrap)?
├── YES → thiserror. Define a concrete error enum per module.
│ Use #[from] for upstream errors so `?` composes cleanly.
│ Never return Box<dyn Error> or Result<T, String>.
│
└── NO → It's a binary / application top layer.
anyhow::Result<T> with .context("...") at each layer.
Use anyhow::bail!() / ensure!() for ad-hoc errors.
Match on root_cause() / downcast_ref() only at boundaries.