h2
h2 copied to clipboard
Implement `Error::source` for `h2::Error`.
This makes it easier to detect an IO error at the bottom of an error
cause chain (e.g. behind a hyper::Error
).
Also, don't implement std::error::Error
for the private error types,
to avoid confusion.
Can we push this forward?
In my case, when a client crashes, the server gets an error similar to this.
// dbg!(&source);
&source = hyper::Error(
Body,
Error {
kind: Io(
Kind(
BrokenPipe,
),
),
},
)
I want to match the error kind to record the event, but recursively downcasting the error to std::io::Error
couldn't work because h2::Error
does not implement std::error::Error#source()
.
This is what I end up with:
fn match_broken_pipe_error(err: &(dyn std::error::Error + 'static)) -> bool {
if let Some(e) = err.downcast_ref::<h2::Error>() {
if let Some(e) = e.get_io() {
if e.kind() == std::io::ErrorKind::BrokenPipe {
return true;
}
}
}
if let Some(source) = err.source() {
match_broken_pipe_error(source)
} else {
false
}
}
The code is much more awkward.
oof...any update on this? Ran into this myself
This is still an issue esp while matching on a stream disconnect in tonic: https://github.com/hyperium/tonic/issues/1579
@seanmonstar what is needed to move this PR forward, happy to start a separate feature branch? This will still affect grpc disonnects since tonic
uses h2
0.3 (so it would have to be backported as well).
I've updated the PR for recent master if anyone would like to review this again :)