Skip to content

Commit

Permalink
fix: Fail gracefully if could not import rpc_status module (#680)
Browse files Browse the repository at this point in the history
* fix: Fail gracefully if could not import rpc_status module

* revert

---------

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
NickGoog and parthea authored Aug 7, 2024
1 parent 6d1b96b commit 7ccbf57
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions google/api_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@

from google.rpc import error_details_pb2


def _warn_could_not_import_grpcio_status():
warnings.warn(
"Please install grpcio-status to obtain helpful grpc error messages.",
ImportWarning,
) # pragma: NO COVER


try:
import grpc

try:
from grpc_status import rpc_status
except ImportError: # pragma: NO COVER
warnings.warn(
"Please install grpcio-status to obtain helpful grpc error messages.",
ImportWarning,
)
_warn_could_not_import_grpcio_status()
rpc_status = None
except ImportError: # pragma: NO COVER
grpc = None
Expand Down Expand Up @@ -560,6 +565,9 @@ def _is_informative_grpc_error(rpc_exc):


def _parse_grpc_error_details(rpc_exc):
if not rpc_status: # pragma: NO COVER
_warn_could_not_import_grpcio_status()
return [], None
try:
status = rpc_status.from_call(rpc_exc)
except NotImplementedError: # workaround
Expand Down

0 comments on commit 7ccbf57

Please sign in to comment.