Skip to content
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

Add RPCErrorConvertible #2143

Merged
merged 2 commits into from
Dec 12, 2024
Merged

Add RPCErrorConvertible #2143

merged 2 commits into from
Dec 12, 2024

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Dec 11, 2024

Motivation:

If an error is thrown from a server RPC then the status sent to the client will always have the unknown error code unless an RPCError is thrown.

Moreover, there are various extensions to gRPC which rely on additional information being stuffed into the metadata. This is difficult and a bit error prone for users to do directly.

We should provide a mechanism whereby errors can be converted to an RPCError such that the appropriate code, message and metadata are sent to the client.

Modifications:

  • Add the RPCErrorConvertible protocol. Conforming types provide appropriate properties to populate an RPCError.
  • Add handling for this in the server executor such that convertible errors are converted into an RPCError.

Result:

Easier for users to propagate an appropriate status

Motivation:

If an error is thrown from a server RPC then the status sent to the
client will always have the unknown error code unless an `RPCError` is
thrown.

Moreover, there are various extensions to gRPC which rely on additional
information being stuffed into the metadata. This is difficult and a bit
error prone for users to do directly.

We should provide a mechanism whereby errors can be converted to an
`RPCError` such that the appropriate code, message and metadata are sent
to the client.

Modifications:

- Add the `RPCErrorConvertible` protocol. Conforming types provide
  appropriate properties to populate an `RPCError`.
- Add handling for this in the server executor such that convertible
  errors are converted into an `RPCError`.

Result:

Easier for users to propagate an appropriate status
@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Dec 11, 2024
@glbrntt glbrntt requested a review from gjcairo December 11, 2024 11:27
@glbrntt glbrntt enabled auto-merge (squash) December 11, 2024 11:27
@glbrntt glbrntt merged commit 13150bd into grpc:main Dec 12, 2024
32 of 33 checks passed
@glbrntt glbrntt deleted the v2/error-throwing branch December 12, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants