rust-lang-deprecated / failure

Error management

Home Page:https://rust-lang-nursery.github.io/failure/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does this exist?

philippludwig opened this issue · comments

I am currently dealing with a library which wraps an std::io::error in a Fail or something like this from this library. All I want is to inspect the ErrorKind to see what IO error occurred, but apparently this is impossible. Why? Why was this created?

Since this is an Issue, here is my request: Please add any kind of documentation on how to extract the raw error from a Cause, a Context or wherever it is hidden. Please add documentation on how to avoid all the abstraction layers this crates added. Ideally this is a one-liner, e.g. get_original_error(). Error seems to have something called inner, but of course its private sigh

Would one of the downcast functions help here?

let orig = std::io::Error::new(ErrorKind::Other, "oh no!");
let err: failure::Error = orig.into();
// Can get it back!
let orig2 = err.downcast::<std::io::Error>().unwrap();
assert_eq!(orig2.kind(), ErrorKind::Other);

You'll need to know the actual concrete error type, though (std::io::Error in your case, but it could be wrapped into some other error type -- check the library you are using).

Why? Why was this created?

It's common to erase the type of an error and only handle one or two variants through downcasting, as Ivan suggested. As for the history of failure, the Fail trait was an experiment in improving the UX of the std::errorr::Error trait. The best properties of the failure::Fail trait have since been upstreamed into std::error::Error.

Since this is an Issue, here is my request: Please add any kind of documentation on how to extract the raw error from a Cause, a Context or wherever it is hidden.

Unfortunately, I'm going to decline this request and close this issue. Failure is deprecated and unmaintained and I would encourage you to ask the maintainers of the library you're depending on if they'd consider moving away from Failure.