error-chain-mini

Crates.ioerror-chain-mini
lib.rserror-chain-mini
version0.2.0
sourcesrc
created_at2018-04-19 07:31:06.478227
updated_at2018-05-25 05:39:54.384454
descriptionerror-chain for minimalist
homepage
repositoryhttps://github.com/kngwyu/error-chain-mini
max_upload_size
id61363
size41,180
Yuji Kanagawa (kngwyu)

documentation

README

error-chain-mini

crates.io documentation Build Status

I think error-chain is good, especially I love chain_err method.

However, sometimes I feel it too complex. I don't want to generate ResultExt and ChainedError by macro. Isn't it confusing?

So, I made this tiny library, providing very straight forward implementation of ResultExt, ChainedError, and some related traits.

In addition, You can use derive to implement your own ErrorKind type.

Example

extern crate error_chain_mini;
#[macro_use]
extern crate error_chain_mini_derive;
use std::io;
use error_chain_mini::*;
use std::error::Error;
#[derive(ErrorKind)]
enum MyErrorKind {
    #[msg(short = "io error", detailed = "inner: {:?}", _0)]
    IoError(io::Error),
    #[msg(short = "index error", detailed = "invalid index: {:?}", _0)]
    IndexEroor(usize),
    TrivialError,
}
type MyError = ChainedError<MyErrorKind>;
type MyResult<T> = Result<T, MyError>;
fn always_fail() -> MyResult<()> {
    Err(MyErrorKind::TrivialError.into_with("Oh my god!"))
}
fn main() {
    assert_eq!("index error invalid index: 10", MyErrorKind::IndexEroor(10).full());
    let chained = always_fail().chain_err("Error in main()");
    assert!(chained.is_err());
    if let Err(chained) = chained {
        assert_eq!(chained.description(), "MyErrorKind::TrivialError");
        assert_eq!(chained.context[0], "Oh my god!");
        assert_eq!(chained.context[1], "Error in main()");
    }
}

Required minimum version of Rust

1.26.0 (match_default_bindings is needed)

License

This project is licensed under either of

at your option.

Commit count: 32

cargo fmt