tailhook/quick-error

pretty-printing with `cause` traversal

Byron opened this issue · 4 comments

Byron commented

Currently I take great of not degenerating any error information. Thus I might end up with hierarchies of errors linked up by their cause().

However, currently displaying the error is manually implemented, and it appears the causes are not printed.

Do you see a way to have the causes followed and printed automatically ?

Yes. You can iterate through all the causes and print them. It should be easy to implement. I don't want that code to go into quick_error itself. But it would be cool to have a crate that does pretty printing.

Once I wanted to do that myself, but it looks like I had not enough time to afford that just yet.

Byron commented

I totally agree - it's easy to do, and something like the code below would do it for most. If generalized, it could be useful in a separate crate.

impl<'a> Display for WithCauses<'a> {
    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
        try!(write!(fmt, "ERROR: {}", self.0));
        let mut cursor = self.0;
        while let Some(err) = cursor.cause() {
            try!(write!(fmt, "\ncaused by: \n{}", err));
            cursor = err;
        }
        try!(write!(fmt, "\n"));
        Ok(())
    }
}

Then it can be used like this:

write!(stderr(), "{}\n", WithCauses(&err)).ok();

Yeah. Let me know if you made a crate for that :)

Byron commented

:). I probably won't, just because it's seems so trivial to get right. On
the other Hand, I will need it in google-apis-rs too ... will let you know
then :D
On Sun, 30 Oct 2016 at 15:51, Paul Colomiets notifications@github.com
wrote:

Yeah. Let me know if you made a crate for that :)


You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub
#29 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAD4hhulgnKXVfeeloHuAnRpeJJRpEOaks5q5K74gaJpZM4KkVCk
.