Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ccbf57

Browse files
NickGoogparthea
andauthored
fix: Fail gracefully if could not import rpc_status module (#680)
* fix: Fail gracefully if could not import rpc_status module * revert --------- Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 6d1b96b commit 7ccbf57

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

google/api_core/exceptions.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@
2828

2929
from google.rpc import error_details_pb2
3030

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+
) # pragma: NO COVER
37+
38+
3139
try:
3240
import grpc
3341

3442
try:
3543
from grpc_status import rpc_status
3644
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()
4146
rpc_status = None
4247
except ImportError: # pragma: NO COVER
4348
grpc = None
@@ -560,6 +565,9 @@ def _is_informative_grpc_error(rpc_exc):
560565

561566

562567
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
563571
try:
564572
status = rpc_status.from_call(rpc_exc)
565573
except NotImplementedError: # workaround

0 commit comments

Comments
 (0)