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
L105: Python Add New Error Types #388
L105: Python Add New Error Types #388
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But please do not merge until 2 weeks after the thread has been posted to the mailing list.
## Rationale | ||
|
||
The Async API [has similar errors](https://github.com/grpc/grpc/blob/v1.57.x/src/python/grpcio/grpc/aio/__init__.py#L23,L24). We're refactoring code so those errors will also be used in Sync API. Adding them to the Sync API will help us keep the two stacks in sync and allow users of the Sync implementation to catch and handle aborts. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to mention that adding this will allow users to type:
try:
do_grpc_stuff()
except grpc.BaseError as e:
# handle error
and be confident that they're catching all gRPC exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also have RpcError
exposed to user, I think we should mention their differences, when should user expect RpcError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If RpcError is not currently a subclass of BaseError, I think we should make it a subclass of BaseError. Ditto for all other exception types. The ultimate goal is to enable the snippet above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense, I'll change RpcError
to be a subclass of BaseError
and add it to this gRFC.
Fix: #33890 In case of abort, currently we don't log anything, this change added an `AbortError` as the default error for abort, if any other error happened, we'll log the error so user will be aware of the other error. Related gRFC: grpc/proposal#388 ### Testing * Tested locally, after this change, any non-AbortError will be logged, sample log: ``` ERROR:grpc._server:Exception happened while abort: Other exception happened! Traceback (most recent call last): File "/usr/local/google/home/xuanwn/.cache/bazel/_bazel_xuanwn/da3828576aa39e99a5c826cc2e2e22fb/sandbox/linux-sandbox/9/execroot/com_github_grpc_grpc/bazel-out/k8-fastbuild/bin/src/python/grpcio_tests/tests/unit/_abort_test.native.runfiles/com_github_grpc_grpc/src/python/grpcio/grpc/_server.py", line 553, in _call_behavior response_or_iterator = behavior(argument, context) File "/usr/local/google/home/xuanwn/.cache/bazel/_bazel_xuanwn/da3828576aa39e99a5c826cc2e2e22fb/sandbox/linux-sandbox/9/execroot/com_github_grpc_grpc/bazel-out/k8-fastbuild/bin/src/python/grpcio_tests/tests/unit/_abort_test.native.runfiles/com_github_grpc_grpc/src/python/grpcio_tests/tests/unit/_abort_test.py", line 95, in abort_with_status_unary_unary_raise_additional_exception raise Exception("Other exception happened!") Exception: Other exception happened! ```
Add two new errors in grpc public API.
Discussion thread: https://groups.google.com/g/grpc-io/c/pG34X9nAa3c