Byron / therror

`thiserror` + killer-feature
Apache License 2.0
6 stars 0 forks source link

derive(Error)

github crates.io docs.rs build status

This library provides a convenient derive macro for the standard library's std::error::Error trait.

[dependencies]
therror = "1.0"

Compiler support: requires rustc 1.56+


Example

use therror::Error;

#[derive(Error, Debug)]
pub enum DataStoreError {
    #[error("data store disconnected")]
    Disconnect(#[from] io::Error),
    #[error("the data for key `{0}` is not available")]
    Redaction(String),
    #[error("invalid header (expected {expected:?}, found {found:?})")]
    InvalidHeader {
        expected: String,
        found: String,
    },
    #[error("unknown data store error")]
    Unknown,
}


Details


Comparison to anyhow

Use therror if you care about designing your own dedicated error type(s) so that the caller receives exactly the information that you choose in the event of failure. This most often applies to library-like code. Use Anyhow if you don't care what error type your functions return, you just want it to be easy. This is common in application-like code.


A fork of therror

This fork was created with the idea of adding a killer-feature to therror which would definitely not make it into therror itself. We shall write more once it is more than an idea.

The idea is to start out at 0.X.Y where X is chosen to denote breaking changes, and Y is tracking the therror baseline while it matters. Once it becomes clear how therror differentiates itself, while retaining compatibility to therror for its baseline features, and once this differentiation becomes mature, we can continue increasing the major version to 2.0.0 and stand alone.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.