From 112049e79f5a5b0a989d85d438a1bd29485f46f7 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 15 Mar 2022 11:35:14 -0400 Subject: [PATCH] fix: allow grpc without grpcio-status (#355) --- google/api_core/exceptions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/google/api_core/exceptions.py b/google/api_core/exceptions.py index 24b65ee0..38fe6e78 100644 --- a/google/api_core/exceptions.py +++ b/google/api_core/exceptions.py @@ -24,15 +24,23 @@ import http.client from typing import Dict from typing import Union +import warnings from google.rpc import error_details_pb2 try: import grpc - from grpc_status import rpc_status + + 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, + ) + rpc_status = None except ImportError: # pragma: NO COVER grpc = None - rpc_status = None # Lookup tables for mapping exceptions from HTTP and gRPC transports. # Populated by _GoogleAPICallErrorMeta