Skip to content

Commit

Permalink
fix(tonic): Expose h2 error instead of reason (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla authored Jan 12, 2022
1 parent 366d888 commit a33e15a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
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

0 comments on commit a33e15a

Please sign in to comment.