-
Notifications
You must be signed in to change notification settings - Fork 225
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
Merged
XuanWang-Amos
merged 4 commits into
grpc:master
from
XuanWang-Amos:expose_new_error_type
Sep 27, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
L105: Python Add New Error Types | ||
---- | ||
* Author(s): XuanWang-Amos | ||
* Approver: gnossen | ||
* Status: In Review | ||
* Implemented in: Python | ||
* Last updated: 08/31/2023 | ||
* Discussion at: https://groups.google.com/g/grpc-io/c/pG34X9nAa3c | ||
|
||
## Abstract | ||
|
||
* Add two new errors in grpc public API: | ||
* BaseError | ||
* AbortError | ||
* Also changed RpcError to be a subclass of BaseError. | ||
|
||
## Background | ||
|
||
In case of abort, currently we don't log anything, exposing those error types allows user to catch and handle aborts if they want. | ||
|
||
## Proposal | ||
|
||
1. Add AbortError and BaseError in public API. | ||
2. Change RpcError to be a subclass of BaseError. | ||
|
||
|
||
## 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. | ||
|
||
We also plan to change RpcError to be a subclass of BaseError so that all grpc errors are a subclass of BaseError, this will allow users to catching all gRPC exceptions use code like this: | ||
|
||
```Python | ||
try: | ||
do_grpc_stuff() | ||
except grpc.BaseError as e: | ||
# handle error | ||
``` | ||
|
||
## Implementation | ||
|
||
And and check AbortError while abort : https://github.com/grpc/grpc/pull/33969 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 ofBaseError
and add it to this gRFC.