failure icon indicating copy to clipboard operation
failure copied to clipboard

Document how to display errors

Open matklad opened this issue 7 years ago • 1 comments

Hi!

I am learning failure right now (and it seems just awesome!), however, I find one aspect of usage of Failure undocumented. Specifically, I am not sure what information gets displayed to the user in which cases (specifically, are causes included?).

Here's what I found:

  • using format!("{}"), only prints the leaf error.
  • using format!("{:?}") prints the whole chain, but uses internal representation for errors (though, display representations for causes). It also prints the backtrace
  • .unwraping an Error works like "{:?}"
  • there's no method to get a human readable representation of error together with its causes. To get one, you'll need something like this:
    let mut buff = String::new();
    for c in e.causes() {
        buff += &format!("{}\n", c);
    }
    

Does this sound right? Are there any existing best-practices on how to display an Error in various situations (i.e, in the console, in the text of HTML response, in a field of a JSON response)?

matklad avatar Feb 07 '18 21:02 matklad

Ran into this as well today when looking into switching from error-chain to failure and couldn't really find in any of the documentation or tutorials of how to properly and nicely write out the cause chain.

So for new users it would definitely be great to establish and document some good best practices here

repi avatar Jun 06 '18 20:06 repi