Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 65b5df3

Browse files
committed
Show causes in simple example
1 parent 82e5774 commit 65b5df3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/simple.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
#[macro_use]
22
extern crate failure;
33

4+
use failure::Fail;
5+
46
#[derive(Debug, Fail)]
57
#[fail(display = "my error")]
68
struct MyError;
79

8-
fn bad_function() -> Result<(), MyError> {
9-
Err(MyError)
10+
#[derive(Debug, Fail)]
11+
#[fail(display = "my wrapping error")]
12+
struct WrappingError(#[fail(cause)] MyError);
13+
14+
fn bad_function() -> Result<(), WrappingError> {
15+
Err(WrappingError(MyError))
1016
}
1117

1218
fn main() {
13-
println!("{}", bad_function().unwrap_err());
19+
for cause in Fail::iter_causes(&bad_function().unwrap_err()) {
20+
println!("{}", cause);
21+
}
1422
}

0 commit comments

Comments
 (0)