Build Status Latest Version

error-chain - Consistent error handling for Rust

error-chain is a crate for dealing with Rust error boilerplate. It provides a few unique features:

Documentation.

Quick start

Add this to Cargo.toml, under [dependencies]:

toml error-chain = "0.4"

Write this at the top of your crate:

```rust

![recursion_limit = "1024"];

```

Again near the top of your crate, import the error_chain crate and its macros:

```rust

[macro_use]

extern crate error_chain; ```

Add an errors module to your crate:

rust mod errors;

Add a file for that module called errors.rs and put this inside:

rust error_chain! { }

That's the setup. Now when writing modules for your crate, import everything from the errors module:

rust use errors::*;

Create functions that return Result, which is defined by the error_chain! macro, and start chaining errors!

```rust fn doerrorpronework() -> Result<()> { let file = try!(File::open("foo").chainerr(|| "couldn't open file")); try!(file.writestr("important").chainerr(|| "couldn't write file"));

Ok(())

} ```

License

MIT/Apache-2.0