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
Support gRPC exception handler for client-side #5351
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.
Thanks, @jrhee17! 👍
* via request metadata. | ||
*/ | ||
public static final ClientOption<GrpcExceptionHandlerFunction> EXCEPTION_HANDLER = | ||
ClientOption.define("EXCEPTION_HANDLER", (ctx, cause, metadata) -> null); |
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.
Minor) Should we provide the default exception handler with this option?
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.
Sorry, I don't think I understood your intention 😅
Do you mean you prefer that (ctx, cause, metadata) -> null
is defined as the "DEFAULT" exception handler somewhere? (so that GrpcExceptionHandlerFunction
is non-null overall?)
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 guess (ctx, cause, metadata) -> null
is the default exception handler which returns null so that the status from statusFromThrowable
is used.
armeria/grpc/src/main/java/com/linecorp/armeria/internal/common/grpc/GrpcStatus.java
Lines 115 to 122 in d30db0c
if (exceptionHandler != null) { | |
final Status status = exceptionHandler.apply(ctx, t, metadata); | |
if (status != null) { | |
return status; | |
} | |
} | |
return statusFromThrowable(t); |
I think we can explicitly call
(ctx, cause, metadata) -> GrpcStatus.fromThrowable(cause)
or leave a comment about why null is returned to make it clearer. 🤔
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.
Updated as suggested 👍
grpc/src/main/java/com/linecorp/armeria/client/grpc/GrpcClientBuilder.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 great, thanks! 👍 👍 👍
* Sets the {@link CallCredentials} that carries credential data that will be propagated to the server | ||
* via request 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.
This isn't revised. 😉
* via request metadata. | ||
*/ | ||
public static final ClientOption<GrpcExceptionHandlerFunction> EXCEPTION_HANDLER = | ||
ClientOption.define("EXCEPTION_HANDLER", (ctx, cause, metadata) -> null); |
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 guess (ctx, cause, metadata) -> null
is the default exception handler which returns null so that the status from statusFromThrowable
is used.
armeria/grpc/src/main/java/com/linecorp/armeria/internal/common/grpc/GrpcStatus.java
Lines 115 to 122 in d30db0c
if (exceptionHandler != null) { | |
final Status status = exceptionHandler.apply(ctx, t, metadata); | |
if (status != null) { | |
return status; | |
} | |
} | |
return statusFromThrowable(t); |
I think we can explicitly call
(ctx, cause, metadata) -> GrpcStatus.fromThrowable(cause)
or leave a comment about why null is returned to make it clearer. 🤔
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #5351 +/- ##
============================================
- Coverage 73.94% 73.69% -0.26%
- Complexity 20104 20107 +3
============================================
Files 1730 1741 +11
Lines 74161 74369 +208
Branches 9465 9483 +18
============================================
- Hits 54841 54804 -37
- Misses 14844 15030 +186
- Partials 4476 4535 +59 ☔ View full report in Codecov by Sentry. |
Let me go ahead and merge this 🙇 Thanks for the review all |
Motivation:
This PR attempts to support
GrpcExceptionHandlerFunction
for gRPC client sideModifications:
GrpcClientBuilder.exceptionHandler
which accepts aGrpcExceptionHandlerFunction
GrpcStatus.fromThrowable(Throwable)
calls to useGrpcStatus.fromThrowable(GrpcStatusFunction, RequestContext, Throwable, Metadata)
insteadResult: