From a33e15a387a6ca1844748346904d28cb4caae84b Mon Sep 17 00:00:00 2001 From: Robin Lambertz Date: Wed, 12 Jan 2022 22:33:24 +0100 Subject: [PATCH] fix(tonic): Expose h2 error instead of reason (#883) --- tonic/src/status.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tonic/src/status.rs b/tonic/src/status.rs index e2aa656a3..b50f6e55f 100644 --- a/tonic/src/status.rs +++ b/tonic/src/status.rs @@ -325,7 +325,7 @@ impl Status { #[cfg(feature = "transport")] let err = match err.downcast::() { Ok(h2) => { - return Ok(Status::from_h2_error(&*h2)); + return Ok(Status::from_h2_error(h2)); } Err(err) => err, }; @@ -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) -> Status { // See https://github.com/grpc/grpc/blob/3977c30/doc/PROTOCOL-HTTP2.md#errors let code = match err.reason() { Some(h2::Reason::NO_ERROR) @@ -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); - status.source = error; + status.source = Some(err); status } @@ -632,7 +628,7 @@ fn invalid_header_value_byte(err: Error) -> Status { #[cfg(feature = "transport")] impl From for Status { fn from(err: h2::Error) -> Self { - Status::from_h2_error(&err) + Status::from_h2_error(Box::new(err)) } }