#newtype #failure #error #command-line #cli

exitfailure

A basic newtype wrappers for use with ? in main

10 releases (4 breaking)

Uses old Rust 2015

0.5.1 Aug 3, 2018
0.5.0 Jul 27, 2018
0.4.1 Jun 18, 2018
0.3.0 May 30, 2018
0.1.0 May 13, 2018

#13 in #failure

Download history 1067/week @ 2021-08-10 733/week @ 2021-08-17 1023/week @ 2021-08-24 778/week @ 2021-08-31 898/week @ 2021-09-07 1010/week @ 2021-09-14 916/week @ 2021-09-21 1008/week @ 2021-09-28 1024/week @ 2021-10-05 1740/week @ 2021-10-12 1460/week @ 2021-10-19 1379/week @ 2021-10-26 1687/week @ 2021-11-02 1740/week @ 2021-11-09 1673/week @ 2021-11-16 1633/week @ 2021-11-23

7,231 downloads per month
Used in less than 121 crates

MIT/Apache

12KB
69 lines

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.

Dependencies

~61KB