Skip to content

Commit

Permalink
fix(tonic): don't include error's cause in Display impl (#633)
Browse files Browse the repository at this point in the history
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 `tonic::transport::Error` include its cause in their
`Display` impl we get the sources more than once.

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

Fixes #632
  • Loading branch information
davidpdrsn authored May 27, 2021
1 parent 9478fac commit 31a3468
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions tonic/src/transport/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ impl fmt::Debug for Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(source) = &self.inner.source {
write!(f, "{}: {}", self.description(), source)
} else {
f.write_str(self.description())
}
f.write_str(self.description())
}
}

Expand Down

0 comments on commit 31a3468

Please sign in to comment.