-
Notifications
You must be signed in to change notification settings - Fork 926
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 Status
parameter to GrpcExceptionHandlerFunction.apply()
method.
#5786
Conversation
Motivation: When an exception is raised, `GrpcService` creates a new `Status` from `Status.getCause()` via `GrpcExceptionHandlerFunction`. This can result in sending an incorrect status in certain situations: - If the original exception is a `StatusRuntimeException` containing the `Status` that the user wants to send. - The original exception has already been converted into a `Status` via `Status.fromThrowable()`: https://github.com/grpc/grpc-java/blob/5770114d08dcd352f2288ef52d17e1833530323c/stub/src/main/java/io/grpc/stub/ServerCalls.java#L389 - This converted `Status` is ignored and a new, potentially incorrect `Status` is created by `GrpcExceptionHandlerFunction` and sent. Modifications: - Added a `Status` parameter to the `GrpcExceptionHandlerFunction.apply()` method. - Updated the default implementation of `GrpcExceptionHandlerFunction.of()` to return the provided `Status` if it is not an unknown status. Result: - The `GrpcExceptionHandlerFunction` now properly handles and returns the correct `Status`. - (Breaking) The `apply` method of `GrpcExceptionHandlerFunction` now takes a `Status`.
grpc/src/main/java/com/linecorp/armeria/common/grpc/DefaultGrpcExceptionHandlerFunction.java
Outdated
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/common/grpc/GrpcExceptionHandlerFunction.java
Outdated
Show resolved
Hide resolved
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.
Looks good to me once @trustin 's comments are addressed 👍 👍 👍
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.
Thanks, @minwoox!
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.
Thanks! Left a nit for @Nullable
.
@@ -11,7 +11,7 @@ class GrpcExceptionHandler implements GrpcExceptionHandlerFunction { | |||
|
|||
@Nullable | |||
@Override | |||
public Status apply(RequestContext ctx, Throwable cause, Metadata metadata) { | |||
public Status apply(RequestContext ctx, Status status, Throwable cause, Metadata 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.
public Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) { | |
public Status apply(RequestContext ctx, @Nullable Status status, Throwable cause, Metadata metadata) { |
@@ -40,15 +40,15 @@ public interface GoogleGrpcExceptionHandlerFunction extends GrpcExceptionHandler | |||
|
|||
@Nullable | |||
@Override | |||
default Status apply(RequestContext ctx, Throwable throwable, Metadata metadata) { | |||
default Status apply(RequestContext ctx, Status status, Throwable throwable, Metadata 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.
default Status apply(RequestContext ctx, Status status, Throwable throwable, Metadata metadata) { | |
default Status apply(RequestContext ctx, @Nullable Status status, Throwable throwable, Metadata metadata) { |
@@ -35,9 +35,9 @@ public UnwrappingGrpcExceptionHandleFunction(GrpcExceptionHandlerFunction handle | |||
} | |||
|
|||
@Override | |||
public @Nullable Status apply(RequestContext ctx, Throwable cause, Metadata metadata) { | |||
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata 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.
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) { | |
public @Nullable Status apply(RequestContext ctx, @Nullable Status status, Throwable cause, Metadata metadata) { |
@@ -145,7 +145,7 @@ private static class FirstGrpcExceptionHandler implements GrpcExceptionHandlerFu | |||
private static class SecondGrpcExceptionHandler implements GrpcExceptionHandlerFunction { | |||
|
|||
@Override | |||
public @Nullable Status apply(RequestContext ctx, Throwable cause, Metadata metadata) { | |||
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata 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.
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) { | |
public @Nullable Status apply(RequestContext ctx, @Nullable Status status, Throwable cause, Metadata metadata) { |
@@ -133,7 +133,7 @@ void exceptionHandler() { | |||
private static class FirstGrpcExceptionHandler implements GrpcExceptionHandlerFunction { | |||
|
|||
@Override | |||
public @Nullable Status apply(RequestContext ctx, Throwable cause, Metadata metadata) { | |||
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata 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.
public @Nullable Status apply(RequestContext ctx, Status status, Throwable cause, Metadata metadata) { | |
public @Nullable Status apply(RequestContext ctx, @Nullable Status status, Throwable cause, Metadata 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.
All addressed. Thanks! 😉
…od. (#5786) Motivation: When an exception is raised, `GrpcService` creates a new `Status` from `Status.getCause()` via `GrpcExceptionHandlerFunction`. This can result in sending an incorrect status in certain situations: - If the original exception is a `StatusRuntimeException` containing the `Status` that the user wants to send. - The original exception has already been converted into a `Status` via `Status.fromThrowable()`: https://github.com/grpc/grpc-java/blob/5770114d08dcd352f2288ef52d17e1833530323c/stub/src/main/java/io/grpc/stub/ServerCalls.java#L389 - This converted `Status` is ignored and a new, potentially incorrect `Status` is created by `GrpcExceptionHandlerFunction` and sent. Modifications: - Added a `Status` parameter to the `GrpcExceptionHandlerFunction.apply()` method. - Updated the default implementation of `GrpcExceptionHandlerFunction.of()` to return the provided `Status` if it is not an unknown status. Result: - The `GrpcExceptionHandlerFunction` now properly handles and returns the correct `Status`. - (Breaking) The `apply` method of `GrpcExceptionHandlerFunction` now takes a `Status`.
Motivation:
When an exception is raised,
GrpcService
creates a newStatus
fromStatus.getCause()
viaGrpcExceptionHandlerFunction
. This can result in sending an incorrect status in certain situations:StatusRuntimeException
containing theStatus
that the user wants to send.Status
viaStatus.fromThrowable()
: https://github.com/grpc/grpc-java/blob/5770114d08dcd352f2288ef52d17e1833530323c/stub/src/main/java/io/grpc/stub/ServerCalls.java#L389Status
is ignored and a new, potentially incorrectStatus
is created byGrpcExceptionHandlerFunction
and sent.Modifications:
Status
parameter to theGrpcExceptionHandlerFunction.apply()
method.GrpcExceptionHandlerFunction.of()
to return the providedStatus
if it is not an unknown status.Result:
GrpcExceptionHandlerFunction
now properly handles and returns the correctStatus
.apply
method ofGrpcExceptionHandlerFunction
now takes aStatus
.