Skip to content

Commit a33e15a

Browse files
authored
fix(tonic): Expose h2 error instead of reason (#883)
1 parent 366d888 commit a33e15a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

tonic/src/status.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl Status {
325325
#[cfg(feature = "transport")]
326326
let err = match err.downcast::<h2::Error>() {
327327
Ok(h2) => {
328-
return Ok(Status::from_h2_error(&*h2));
328+
return Ok(Status::from_h2_error(h2));
329329
}
330330
Err(err) => err,
331331
};
@@ -340,7 +340,7 @@ impl Status {
340340

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

361361
let mut status = Self::new(code, format!("h2 protocol error: {}", err));
362-
let error = err
363-
.reason()
364-
.map(h2::Error::from)
365-
.map(|err| Box::new(err) as Box<dyn Error + Send + Sync + 'static>);
366-
status.source = error;
362+
status.source = Some(err);
367363
status
368364
}
369365

@@ -632,7 +628,7 @@ fn invalid_header_value_byte<Error: fmt::Display>(err: Error) -> Status {
632628
#[cfg(feature = "transport")]
633629
impl From<h2::Error> for Status {
634630
fn from(err: h2::Error) -> Self {
635-
Status::from_h2_error(&err)
631+
Status::from_h2_error(Box::new(err))
636632
}
637633
}
638634

0 commit comments

Comments
 (0)