Skip to content

Instantly share code, notes, and snippets.

@iopq
Last active December 15, 2018 05:37
Show Gist options
  • Save iopq/66fd8ea54cc4557a1f0115118f876dcf to your computer and use it in GitHub Desktop.
Save iopq/66fd8ea54cc4557a1f0115118f876dcf to your computer and use it in GitHub Desktop.
#[macro_use]
extern crate failure;
use failure::Fail;
#[derive(Debug, Fail)]
#[fail(display = "my error")]
struct MyError;
#[derive(Debug, Fail)]
#[fail(display = "my wrapping error")]
struct WrappingError(#[fail(cause)] MyError);
fn bad_function() -> Result<(), WrappingError> {
Err(WrappingError(MyError))
}
fn main() {
for cause in Fail::iter_causes(&bad_function().unwrap_err()) {
println!("{}", cause);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment