@@ -305,7 +305,6 @@ impl Status {
305
305
Status :: new ( Code :: Unauthenticated , message)
306
306
}
307
307
308
- #[ cfg_attr( not( feature = "transport" ) , allow( dead_code) ) ]
309
308
pub ( crate ) fn from_error_generic (
310
309
err : impl Into < Box < dyn Error + Send + Sync + ' static > > ,
311
310
) -> Status {
@@ -316,7 +315,6 @@ impl Status {
316
315
///
317
316
/// Inspects the error source chain for recognizable errors, including statuses, HTTP2, and
318
317
/// hyper, and attempts to maps them to a `Status`, or else returns an Unknown `Status`.
319
- #[ cfg_attr( not( feature = "transport" ) , allow( dead_code) ) ]
320
318
pub fn from_error ( err : Box < dyn Error + Send + Sync + ' static > ) -> Status {
321
319
Status :: try_from_error ( err) . unwrap_or_else ( |err| {
322
320
let mut status = Status :: new ( Code :: Unknown , err. to_string ( ) ) ;
@@ -342,7 +340,7 @@ impl Status {
342
340
Err ( err) => err,
343
341
} ;
344
342
345
- #[ cfg( feature = "transport " ) ]
343
+ #[ cfg( feature = "server " ) ]
346
344
let err = match err. downcast :: < h2:: Error > ( ) {
347
345
Ok ( h2) => {
348
346
return Ok ( Status :: from_h2_error ( h2) ) ;
@@ -359,7 +357,7 @@ impl Status {
359
357
}
360
358
361
359
// FIXME: bubble this into `transport` and expose generic http2 reasons.
362
- #[ cfg( feature = "transport " ) ]
360
+ #[ cfg( feature = "server " ) ]
363
361
fn from_h2_error ( err : Box < h2:: Error > ) -> Status {
364
362
let code = Self :: code_from_h2 ( & err) ;
365
363
@@ -368,7 +366,7 @@ impl Status {
368
366
status
369
367
}
370
368
371
- #[ cfg( feature = "transport " ) ]
369
+ #[ cfg( feature = "server " ) ]
372
370
fn code_from_h2 ( err : & h2:: Error ) -> Code {
373
371
// See https://github.com/grpc/grpc/blob/3977c30/doc/PROTOCOL-HTTP2.md#errors
374
372
match err. reason ( ) {
@@ -388,7 +386,7 @@ impl Status {
388
386
}
389
387
}
390
388
391
- #[ cfg( feature = "transport " ) ]
389
+ #[ cfg( feature = "server " ) ]
392
390
fn to_h2_error ( & self ) -> h2:: Error {
393
391
// conservatively transform to h2 error codes...
394
392
let reason = match self . code {
@@ -404,7 +402,7 @@ impl Status {
404
402
///
405
403
/// Returns Some if there's a way to handle the error, or None if the information from this
406
404
/// hyper error, but perhaps not its source, should be ignored.
407
- #[ cfg( feature = "transport" ) ]
405
+ #[ cfg( any ( feature = "server" , feature = "channel" ) ) ]
408
406
fn from_hyper_error ( err : & hyper:: Error ) -> Option < Status > {
409
407
// is_timeout results from hyper's keep-alive logic
410
408
// (https://docs.rs/hyper/0.14.11/src/hyper/error.rs.html#192-194). Per the grpc spec
@@ -420,6 +418,7 @@ impl Status {
420
418
return Some ( Status :: cancelled ( err. to_string ( ) ) ) ;
421
419
}
422
420
421
+ #[ cfg( feature = "server" ) ]
423
422
if let Some ( h2_err) = err. source ( ) . and_then ( |e| e. downcast_ref :: < h2:: Error > ( ) ) {
424
423
let code = Status :: code_from_h2 ( h2_err) ;
425
424
let status = Self :: new ( code, format ! ( "h2 protocol error: {}" , err) ) ;
@@ -607,7 +606,7 @@ fn find_status_in_source_chain(err: &(dyn Error + 'static)) -> Option<Status> {
607
606
} ) ;
608
607
}
609
608
610
- #[ cfg( feature = "transport " ) ]
609
+ #[ cfg( feature = "server " ) ]
611
610
if let Some ( timeout) = err. downcast_ref :: < crate :: transport:: TimeoutExpired > ( ) {
612
611
return Some ( Status :: cancelled ( timeout. to_string ( ) ) ) ;
613
612
}
@@ -624,7 +623,7 @@ fn find_status_in_source_chain(err: &(dyn Error + 'static)) -> Option<Status> {
624
623
return Some ( Status :: unavailable ( connect. to_string ( ) ) ) ;
625
624
}
626
625
627
- #[ cfg( feature = "transport" ) ]
626
+ #[ cfg( any ( feature = "server" , feature = "channel" ) ) ]
628
627
if let Some ( hyper) = err
629
628
. downcast_ref :: < hyper:: Error > ( )
630
629
. and_then ( Status :: from_hyper_error)
@@ -671,14 +670,14 @@ fn invalid_header_value_byte<Error: fmt::Display>(err: Error) -> Status {
671
670
)
672
671
}
673
672
674
- #[ cfg( feature = "transport " ) ]
673
+ #[ cfg( feature = "server " ) ]
675
674
impl From < h2:: Error > for Status {
676
675
fn from ( err : h2:: Error ) -> Self {
677
676
Status :: from_h2_error ( Box :: new ( err) )
678
677
}
679
678
}
680
679
681
- #[ cfg( feature = "transport " ) ]
680
+ #[ cfg( feature = "server " ) ]
682
681
impl From < Status > for h2:: Error {
683
682
fn from ( status : Status ) -> Self {
684
683
status. to_h2_error ( )
@@ -927,7 +926,7 @@ mod tests {
927
926
}
928
927
929
928
#[ test]
930
- #[ cfg( feature = "transport " ) ]
929
+ #[ cfg( feature = "server " ) ]
931
930
fn from_error_h2 ( ) {
932
931
use std:: error:: Error as _;
933
932
@@ -944,7 +943,7 @@ mod tests {
944
943
}
945
944
946
945
#[ test]
947
- #[ cfg( feature = "transport " ) ]
946
+ #[ cfg( feature = "server " ) ]
948
947
fn to_h2_error ( ) {
949
948
let orig = Status :: new ( Code :: Cancelled , "stop eet!" ) ;
950
949
let err = orig. to_h2_error ( ) ;
0 commit comments