Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tonic): Expose h2 error instead of reason #883

Merged
merged 1 commit into from Jan 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions tonic/src/status.rs
Expand Up @@ -325,7 +325,7 @@ impl Status {
#[cfg(feature = "transport")]
let err = match err.downcast::<h2::Error>() {
Ok(h2) => {
return Ok(Status::from_h2_error(&*h2));
return Ok(Status::from_h2_error(h2));
}
Err(err) => err,
};
Expand All @@ -340,7 +340,7 @@ impl Status {

// FIXME: bubble this into `transport` and expose generic http2 reasons.
#[cfg(feature = "transport")]
fn from_h2_error(err: &h2::Error) -> Status {
fn from_h2_error(err: Box<h2::Error>) -> Status {
// See https://github.com/grpc/grpc/blob/3977c30/doc/PROTOCOL-HTTP2.md#errors
let code = match err.reason() {
Some(h2::Reason::NO_ERROR)
Expand All @@ -359,11 +359,7 @@ impl Status {
};

let mut status = Self::new(code, format!("h2 protocol error: {}", err));
let error = err
.reason()
.map(h2::Error::from)
.map(|err| Box::new(err) as Box<dyn Error + Send + Sync + 'static>);
status.source = error;
status.source = Some(err);
status
}

Expand Down Expand Up @@ -632,7 +628,7 @@ fn invalid_header_value_byte<Error: fmt::Display>(err: Error) -> Status {
#[cfg(feature = "transport")]
impl From<h2::Error> for Status {
fn from(err: h2::Error) -> Self {
Status::from_h2_error(&err)
Status::from_h2_error(Box::new(err))
}
}

Expand Down