-
Notifications
You must be signed in to change notification settings - Fork 33
Add support for gRPC error metadata propagation #194
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
Open
adparts
wants to merge
3
commits into
eclipse-vertx:main
Choose a base branch
from
adparts:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
vertx-grpc-server/src/main/java/io/vertx/grpc/server/GrpcErrorInfoProvider.java
This file contains hidden or 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,41 @@ | ||
| package io.vertx.grpc.server; | ||
|
|
||
| import io.vertx.core.MultiMap; | ||
| import io.vertx.grpc.common.GrpcStatus; | ||
|
|
||
| /** | ||
| * Interface for providing detailed error information in gRPC server responses. | ||
| * <p> | ||
| * Implementing this interface allows exceptions to expose structured gRPC error details, | ||
| * including a status a descriptive error message, and optional trailers. | ||
| * </p> | ||
| * <p> | ||
| * This design enables custom exceptions to propagate meaningful and rich error context to gRPC clients | ||
| * without coupling to a specific exception class. | ||
| * </p> | ||
| */ | ||
|
|
||
| public interface GrpcErrorInfoProvider { | ||
|
|
||
| /** | ||
| * Returns the GrpcStatus associated with this error. | ||
| * | ||
| * @return the gRPC status | ||
| */ | ||
| GrpcStatus status(); | ||
|
|
||
| /** | ||
| * Returns the gRPC error message to send to the client. | ||
| * | ||
| * @return the error message as a string | ||
| */ | ||
| String message(); | ||
|
|
||
| /** | ||
| * Returns optional key-value trailers to include in the response. | ||
| * Can be {@code null} or empty. | ||
| * | ||
| * @return containing error trailers | ||
| */ | ||
| MultiMap trailers(); | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
I don't think this interface is needed for implementing the feature ? if we can just use directly
StatusExceptionwithout it, then we should do itThere 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.
You're right it's not necessary, but there’s an important reason behind it:
StatusExceptionis final, applications cannot extend it to include additional behavior or metadata relevant to their domain logic. As a result, if we rely solely onStatusException, applications are forced to throw a specific Vert.x class from within their business logic, making the error-handling tightly coupled to the transport layer.The goal of introducing the interface is to decouple the business logic from the transport mechanism. This way, applications can throw their own domain-specific exceptions (e.g. InvalidUserInputException, PaymentRejectedException, etc.) and simply implement the interface to expose gRPC-compatible error data (status, message, metadata).
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.
I personally like the idea of users having the ability to write their own exceptions which are decoupled from the transport layer.
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.
Currently there are not tests using
GrpcErrorInfoProvider, can you explain how this would be used in practice, it is not yet still clear to me how it can be usedThere 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.
Thanks for the review. Let me give a concrete example to clarify the motivation for the interface.
Imagine a typical application structure where we define a base exception for our domain logic, and specific exceptions extend from it. These exceptions should not extend from
StatusException, which is Vert.x/gRPC specific and has nothing to do with our application's business concerns (Furthermore, StatusException is final and we force the application to use it without chance of any subclassing).Example
Then we define a business-specific exception, and we want it to be mappable to a gRPC status, without coupling it to Vert.x types:
Note that:
UserNotFoundExceptionis part of our domain, and extendsAppException.GrpcStatusExceptionto signal to the framework that it knows how to convert itself to a gRPC Status.This keeps our application cleanly decoupled, while still enabling powerful mapping logic on the framework side.
Without this interface, we are forced to use
StatusExceptiondirectly within our application code.StatusExceptionis a final class, meaning we cannot extend it to add application-specific data or behavior that might be relevant (e.g. error codes, metadata, logging context, etc.).This pattern is especially useful in microservice-to-microservice calls, where domain exceptions need to be translated to appropriate gRPC statuses but we still want to keep a clean architecture on the application side.
Hope this clarifies the intent!