Document how to display errors
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 .unwrapingan 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)?
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