#error #backtrace #capture #description #optional #textual #debugging

ebacktrace

A simple error wrapper which captures a backtrace and can carry an optional textual description

6 releases (3 breaking)

0.5.1 Mar 1, 2022
0.5.0 Mar 1, 2022
0.4.0 Feb 13, 2022
0.3.2 Sep 9, 2021
0.2.0 Jun 29, 2021

#898 in Rust patterns

Download history 6/week @ 2024-02-15 27/week @ 2024-02-22 8/week @ 2024-02-29 9/week @ 2024-03-07 5/week @ 2024-03-14 26/week @ 2024-03-28 26/week @ 2024-04-04 3/week @ 2024-04-11

55 downloads per month
Used in 9 crates (8 directly)

BSD-2-Clause OR MIT

14KB
159 lines

License BSD-2-Clause License MIT AppVeyor CI docs.rs crates.io Download numbers dependency status

ebacktrace

Welcome to ebacktrace 🎉

This crate implements a simple error wrapper which captures a backtrace upon creation and can carry an optional textual description of the error.

Example

use ebacktrace::define_error;
use std::fmt::{ self, Display, Formatter };

/// The error kind
#[derive(Debug, Copy, Clone)]
enum ErrorKind {
    MyErrorA,
    Testolope
}
impl Display for ErrorKind {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{:#?}", self)
    }
}
// Define our custom error type
define_error!(Error);

/// A function that will always fail
fn will_fail() -> Result<(), Error<ErrorKind>> {
    Err(ErrorKind::Testolope)?
}

// Will panic with a nice error
if let Err(e) = will_fail() {
    eprintln!("Error: {:?}", e);
    panic!("Fatal error")
}

Features

This crate currently has one feature gate:

  • force_backtrace (disabled by default): If force_backtrace is enable, the backtrace is always captured, regardless whether RUST_BACKTRACE is set or not.

Dependencies

~2.4–3.5MB
~72K SLoC