All Projects → tismith → exitfailure

tismith / exitfailure

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Helpers for easily using failure::Error and others as return types in main() while still giving human-readable error messages.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to exitfailure

retries
Forget about your retry boilerplate
Stars: ✭ 14 (-66.67%)
Mutual labels:  failure
Tenacity
Retrying library for Python
Stars: ✭ 3,472 (+8166.67%)
Mutual labels:  failure
Toxy
Hackable HTTP proxy for resiliency testing and simulated network conditions
Stars: ✭ 2,698 (+6323.81%)
Mutual labels:  failure
Toast
To use it in PCL or .NetStandard projects write this line of code : CrossToastPopUp.Current.ShowToastMessage("Message");
Stars: ✭ 51 (+21.43%)
Mutual labels:  failure
failure
An error handling package for Go.
Stars: ✭ 24 (-42.86%)
Mutual labels:  failure
sbt-flaky
Detect flaky tests with sbt
Stars: ✭ 35 (-16.67%)
Mutual labels:  failure
docker-chaos-monkey
A Chaos Monkey system for Docker Swarm
Stars: ✭ 30 (-28.57%)
Mutual labels:  failure
toaster
Incremental failure injection in C
Stars: ✭ 15 (-64.29%)
Mutual labels:  failure

exitfailure - convenient newtype wrappers for using ? in main()

Build Status Build status codecov

exitfailure provides some newtype wrappers to help with using ? in main().

It is intended to be used with rust 1.26 and above's "? in main()" feature (see the tracking issue here).

The primary items exported by this library are:

  • ExitFailure: a wrapper around failure::Error to allow ? printing from main to present a nicer error message, including any available context and backtrace.

  • ExitDisplay<E>: a wrapper around E: std::fmt::Display to allow the error message from main to use Display and not Debug.

For more information, including more details on the types, please see the API Documentation.

Example:

#[macro use] extern crate failure;
extern crate exitfailure;

use failure::ResultExt;
use exitfailure::ExitFailure;

fn main() -> Result<(), ExitFailure> {
     Ok(some_fn()?)
}

fn some_fn() -> Result<(), failure::Error> {
     let error = Err(failure::err_msg("root cause failure"));
     Ok(error.context("this is some context".to_string())?)
}

This will print, when executed:

Error: this is some context
Info: caused by root cause failure

If the environment variable RUST_BACKTRACE=1 is set, then the printing will include whatever backtrace information is provided by the failure::Error that is being wrapped.

License

Licensed under either of

at your option.

Contribution

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].