Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit060b339

Browse 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 parent214d88b commit060b339

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

‎google/api_core/exceptions.py‎

Lines 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+
exceptNotImplementedError:# workaround
493+
return []
494+
491495
ifnotstatus:
492496
return []
497+
493498
possible_errors= [
494499
error_details_pb2.BadRequest,
495500
error_details_pb2.PreconditionFailure,

‎tests/unit/test_exceptions.py‎

Lines 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
assertexception.response==error
238238

239239

240+
@pytest.mark.skipif(grpcisNone,reason="No grpc")
241+
deftest_from_grpc_error_bare_call():
242+
message="Testing"
243+
244+
classTestingError(grpc.Call,grpc.RpcError):
245+
def__init__(self,exception):
246+
self.exception=exception
247+
248+
defcode(self):
249+
returnself.exception.grpc_status_code
250+
251+
defdetails(self):
252+
returnmessage
253+
254+
nested_message="message"
255+
error=TestingError(exceptions.GoogleAPICallError(nested_message))
256+
257+
exception=exceptions.from_grpc_error(error)
258+
259+
assertisinstance(exception,exceptions.GoogleAPICallError)
260+
assertexception.codeisNone
261+
assertexception.grpc_status_codeisNone
262+
assertexception.message==message
263+
assertexception.errors== [error]
264+
assertexception.response==error
265+
assertexception.details== []
266+
267+
240268
defcreate_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)

[8]ページ先頭

©2009-2025 Movatter.jp