Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion google/api_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,14 @@ def _is_informative_grpc_error(rpc_exc):


def _parse_grpc_error_details(rpc_exc):
status = rpc_status.from_call(rpc_exc)
try:
status = rpc_status.from_call(rpc_exc)
except NotImplementedError: # workaround
return []

if not status:
return []

possible_errors = [
error_details_pb2.BadRequest,
error_details_pb2.PreconditionFailure,
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,34 @@ def test_from_grpc_error_non_call():
assert exception.response == error


@pytest.mark.skipif(grpc is None, reason="No grpc")
def test_from_grpc_error_bare_call():
message = "Testing"

class TestingError(grpc.Call, grpc.RpcError):
def __init__(self, exception):
self.exception = exception

def code(self):
return self.exception.grpc_status_code

def details(self):
return message

nested_message = "message"
error = TestingError(exceptions.GoogleAPICallError(nested_message))

exception = exceptions.from_grpc_error(error)

assert isinstance(exception, exceptions.GoogleAPICallError)
assert exception.code is None
assert exception.grpc_status_code is None
assert exception.message == message
assert exception.errors == [error]
assert exception.response == error
assert exception.details == []


def create_bad_request_details():
bad_request_details = error_details_pb2.BadRequest()
field_violation = bad_request_details.field_violations.add()
Expand Down