error-chain - Consistent error handling for Rust
error-chain
is a crate for dealing with Rust error boilerplate. It
provides a few unique features:
- No error is ever discarded. This library primarily makes it easy to
"chain" errors with the
chain_err
method. - Introducing new errors is trivial. Simple errors can be introduced at the error site with just a string.
- Errors can create and propagate backtraces.
Quick start
Add this to Cargo.toml, under [dependencies]
:
= "0.4"
Write this at the top of your crate:
;
Again near the top of your crate, import the error_chain
crate and its macros:
extern crate error_chain;
Add an errors
module to your crate:
Add a file for that module called errors.rs
and put this inside:
error_chain!
That's the setup. Now when writing modules for your crate,
import everything from the errors
module:
use *;
Create functions that return Result
, which is defined by
the error_chain!
macro, and start chaining errors!
License
MIT/Apache-2.0