Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 060b339

Browse filesBrowse files
authored
fix: handle bare 'grpc.Call' in 'from_grpc_error' (#298)
* fix: handle bare 'grpc.Call' in 'from_grpc_error' Fixes: #297. * tests: add assertion for 'exception.details'
1 parent 214d88b commit 060b339
Copy full SHA for 060b339

File tree

2 files changed

+34
-1
lines changed
Filter options

2 files changed

+34
-1
lines changed

‎google/api_core/exceptions.py

Copy file name to clipboardExpand all lines: google/api_core/exceptions.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,14 @@ def _is_informative_grpc_error(rpc_exc):
487487

488488

489489
def _parse_grpc_error_details(rpc_exc):
490-
status = rpc_status.from_call(rpc_exc)
490+
try:
491+
status = rpc_status.from_call(rpc_exc)
492+
except NotImplementedError: # workaround
493+
return []
494+
491495
if not status:
492496
return []
497+
493498
possible_errors = [
494499
error_details_pb2.BadRequest,
495500
error_details_pb2.PreconditionFailure,

‎tests/unit/test_exceptions.py

Copy file name to clipboardExpand all lines: tests/unit/test_exceptions.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,34 @@ def test_from_grpc_error_non_call():
237237
assert exception.response == error
238238

239239

240+
@pytest.mark.skipif(grpc is None, reason="No grpc")
241+
def test_from_grpc_error_bare_call():
242+
message = "Testing"
243+
244+
class TestingError(grpc.Call, grpc.RpcError):
245+
def __init__(self, exception):
246+
self.exception = exception
247+
248+
def code(self):
249+
return self.exception.grpc_status_code
250+
251+
def details(self):
252+
return message
253+
254+
nested_message = "message"
255+
error = TestingError(exceptions.GoogleAPICallError(nested_message))
256+
257+
exception = exceptions.from_grpc_error(error)
258+
259+
assert isinstance(exception, exceptions.GoogleAPICallError)
260+
assert exception.code is None
261+
assert exception.grpc_status_code is None
262+
assert exception.message == message
263+
assert exception.errors == [error]
264+
assert exception.response == error
265+
assert exception.details == []
266+
267+
240268
def create_bad_request_details():
241269
bad_request_details = error_details_pb2.BadRequest()
242270
field_violation = bad_request_details.field_violations.add()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.