Skip to content

Conversation

davidpdrsn
Copy link
Member

At Embark we have a little helper function that converts a &dyn std::error::Error into a String by walking the full chain of sources
(with std::error::Error::source) and joining them into a String.

We use that where we log errors to get as much information as possible
about whats causing an error. Works particularly well with anyhow's
.context() method.

However since hyper::Error and ConnectError include their cause
their Display impl we get the sources more than once. For error
example we're seeing logs like this:

WARN foo::bar::baz > Internal error: error trying to connect: tcp connect error:
A connection attempt failed because the connected party did not properly respond
after a period of time, or established connection failed because connected host
has failed to respond. (os error 10060) -> tcp connect error: A connection
attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has
failed to respond. (os error 10060) -> A connection attempt failed because the
connected party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond. (os error 10060)

As the cause can already be obtained through std::error::Error::source
no information should be lost by doing this.

@davidpdrsn davidpdrsn added the A-error Area: error handling label May 7, 2021
@davidpdrsn davidpdrsn requested a review from seanmonstar May 7, 2021 11:00
At Embark we have a little helper function that converts a `&dyn
std::error::Error` into a `String` by walking the full chain of sources
(with `std::error::Error::source`) and joining them into a `String`.

We use that where we log errors to get as much information as possible
about whats causing an error. Works particularly well with anyhow's
`.context()` method.

However since `hyper::Error` and `ConnectError` include their cause
their `Display` impl we get the sources more than once. For error
example we're seeing logs like this:

```
WARN foo::bar::baz > Internal error: error trying to connect: tcp
connect error: A connection attempt failed because the connected party
did not properly respond after a period of time, or established
connection failed because connected host has failed to respond. (os
error 10060) -> tcp connect error: A connection attempt failed because
the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to
respond. (os error 10060) -> A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to
respond. (os error 10060)
```

As the cause can already be obtained through `std::error::Error::source`
no information should be lost by doing this.
@davidpdrsn davidpdrsn force-pushed the david/fix-error-display branch from ad8d289 to 5d14c61 Compare May 7, 2021 13:42
@repi
Copy link

repi commented Aug 4, 2021

Would be great to get this in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-error Area: error handling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants