File tree 2 files changed +13
-5
lines changed
2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 28
28
29
29
from google .rpc import error_details_pb2
30
30
31
+
32
+ def _warn_could_not_import_grpcio_status ():
33
+ warnings .warn (
34
+ "Please install grpcio-status to obtain helpful grpc error messages." ,
35
+ ImportWarning ,
36
+ )
37
+
38
+
31
39
try :
32
40
import grpc
33
41
34
42
try :
35
43
from grpc_status import rpc_status
36
44
except ImportError : # pragma: NO COVER
37
- warnings .warn (
38
- "Please install grpcio-status to obtain helpful grpc error messages." ,
39
- ImportWarning ,
40
- )
45
+ _warn_could_not_import_grpcio_status ()
41
46
rpc_status = None
42
47
except ImportError : # pragma: NO COVER
43
48
grpc = None
@@ -560,6 +565,9 @@ def _is_informative_grpc_error(rpc_exc):
560
565
561
566
562
567
def _parse_grpc_error_details (rpc_exc ):
568
+ if not rpc_status : # pragma: NO COVER
569
+ _warn_could_not_import_grpcio_status ()
570
+ return [], None
563
571
try :
564
572
status = rpc_status .from_call (rpc_exc )
565
573
except NotImplementedError : # workaround
Original file line number Diff line number Diff line change @@ -392,4 +392,4 @@ def test_error_details_from_grpc_response_unknown_error():
392
392
exception .reason is None
393
393
and exception .domain is None
394
394
and exception .metadata is None
395
- )
395
+ )
You can’t perform that action at this time.
0 commit comments