track_panic

Macro track_panic 

Source
macro_rules! track_panic {
    ($error:expr) => { ... };
    ($error:expr; $($value:expr),+) => { ... };
    ($error_kind:expr, $message:expr) => { ... };
    ($error:expr, $message:expr; $($value:expr),+) => { ... };
    ($error_kind:expr, $($format_arg:tt)+) => { ... };
}
Expand description

Error trackable variant of the standard panic! macro.

This returns an TrackableError object as the result value of the calling function, instead of aborting the current thread.

Conceptually, track_panic!(error) is equivalent to the following code:

use trackable::Trackable;
use trackable::error::TrackableError;

let e = TrackableError::from(error); // Converts to `TrackableError`
let e = track!(e);                   // Tracks this location
Err(e)?;                             // Returns from the current function

ยงExamples

use trackable::error::{Failed, Failure};

fn foo<F>(f: F) -> Result<(), Failure> where F: FnOnce() -> Result<(), Failure> { f() }

let e = foo(|| track_panic!(Failed) ).err().unwrap();
assert_eq!(format!("\n{}", e).replace('\\', "/"), r#"
Failed
HISTORY:
  [0] at src/macros.rs:10
"#);

let e = foo(|| track_panic!(Failed, "something {}", "wrong") ).err().unwrap();
assert_eq!(format!("\n{}", e).replace('\\', "/"), r#"
Failed (cause; something wrong)
HISTORY:
  [0] at src/macros.rs:17
"#);