Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fail gracefully if could not import rpc_status module #680

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)


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
Loading