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

Support custom json marshaller for unframed gRPC error #5555

Merged

Conversation

sato9818
Copy link
Contributor

@sato9818 sato9818 commented Apr 2, 2024

Motivation:

  • A user can't use custom JSON marshaller for unframed grpc error.

Modifications:

  • Implement UnframedGrpcErrorHandlerBuilder which takes a custom json marshaller

Result:

@sato9818 sato9818 changed the title Support custom json marshaller for unframed gRPC error [WIP] Support custom json marshaller for unframed gRPC error Apr 2, 2024
Copy link

codecov bot commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 8.00000% with 46 lines in your changes are missing coverage. Please review.

Project coverage is 74.05%. Comparing base (b8eb810) to head (9c3e53e).
Report is 154 commits behind head on main.

❗ Current head 9c3e53e differs from pull request most recent head 09f782f. Consider uploading reports for the commit 09f782f to get more accurate results

Files Patch % Lines
...a/server/grpc/UnframedGrpcErrorHandlerBuilder.java 0.00% 40 Missing ⚠️
...ria/server/grpc/UnframedGrpcErrorResponseType.java 0.00% 3 Missing ⚠️
.../armeria/server/grpc/UnframedGrpcErrorHandler.java 0.00% 2 Missing ⚠️
...armeria/server/grpc/UnframedGrpcErrorHandlers.java 80.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5555      +/-   ##
============================================
+ Coverage     73.95%   74.05%   +0.09%     
- Complexity    20115    20982     +867     
============================================
  Files          1730     1821      +91     
  Lines         74161    77352    +3191     
  Branches       9465     9882     +417     
============================================
+ Hits          54847    57280    +2433     
- Misses        14837    15421     +584     
- Partials       4477     4651     +174     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ikhoon ikhoon added new feature sprint Issues for OSS Sprint participants labels Apr 2, 2024
@sato9818 sato9818 changed the title [WIP] Support custom json marshaller for unframed gRPC error Support custom json marshaller for unframed gRPC error Apr 10, 2024
@sato9818 sato9818 marked this pull request as ready for review April 10, 2024 02:13
@sato9818 sato9818 requested a review from trustin April 10, 2024 02:13
@sato9818 sato9818 requested a review from trustin April 11, 2024 09:40
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor things - thanks for your patience!

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nits, but it looks good! 👍

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice and useful! Thanks, @sato9818. 🙇‍♂️🙇‍♂️

@@ -110,7 +114,8 @@ static UnframedGrpcErrorHandler of(UnframedGrpcStatusMappingFunction statusMappi
* @param statusMappingFunction The function which maps the {@link Throwable} or gRPC {@link Status} code
* to an {@link HttpStatus} code.
*/
static UnframedGrpcErrorHandler ofJson(UnframedGrpcStatusMappingFunction statusMappingFunction) {
static UnframedGrpcErrorHandler ofJson(
UnframedGrpcStatusMappingFunction statusMappingFunction, MessageMarshaller jsonMarshaller) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional) This class becomes larger and more complex compared to its initial implementation. I think it's time to refactor. Are you interested in sending a follow/up PR to extract the code into TextUnframedGrpcErrorHandler and JsonUnframedGrpcErrorHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!

/**
* Constructs a {@link UnframedGrpcErrorHandler} to handle unframed gRPC errors.
*/
public final class UnframedGrpcErrorHandlerBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public final class UnframedGrpcErrorHandlerBuilder {
@UnstableApi
public final class UnframedGrpcErrorHandlerBuilder {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should we use @Unstable generally?
I'm just curious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add @UnstableApi for new public APIs. It is best not to produce any breaking changes. However, it is difficult to make an API stable from the start. @UnstableApi is a marker that the API can be changed in a minor update.

@sato9818 sato9818 requested a review from ikhoon April 15, 2024 02:08
Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM! 🙇‍♂️

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ikhoon ikhoon merged commit 1d268aa into line:main Apr 17, 2024
16 checks passed
clayburn added a commit to clayburn/armeria that referenced this pull request Apr 24, 2024
* upstream/main:
  Allow `{Service,Server}ErrorHandler.renderStatus()` to access `ServiceRequestContext` (line#5634)
  Bump com.gradle.enterprise from 3.16.2 to 3.17 (line#5559)
  Bump com.gradle.common-custom-user-data-gradle-plugin from 2.0 to 2.0.1 (line#5618)
  Add SchemeAndAuthority class which is in charge of authority normalization (line#5561)
  [Issue-5581] Change into transitive dependency(netty.transport.native.unix.common) (line#5623)
  Make @description annotation at super class/interface work (line#5562)
  Support `ResponseEntity` in annotated service instead of `HttpResult` (line#5586)
  Update public suffix list (line#5625)
  Wait until buffers are released in `ExceedingServiceMaxContentLengthTest.maxContentLength` (line#5600)
  Add the release note for 1.28.2 (line#5615)
  Fixed bug where a request timeout is scheduled after receiving the entire body (line#5614)
  Support custom json marshaller for unframed gRPC error (line#5555)
  Update public suffix list (line#5612)
trustin pushed a commit that referenced this pull request May 2, 2024
Motivation:

Refactor `UnframedGrpcErrorHandlers`.
#5555 (comment)

Modifications:

- Create `TextUnframedGrpcErrorHandler` for a plaintext format response.
- Create `JsonUnframedGrpcErrorHandler` for a JSON format response.
- Create `DefaultUnframedGrpcErrorHandler` for a default error handler.

Result:

- Seperate `UnframedGrpcErrorHandlers` into three classes,
`TextUnframedGrpcErrorHandler`, `JsonUnframedGrpcErrorHandler` and
`DefaultUnframedGrpcErrorHandler`.

---------

Co-authored-by: minwoox <songmw725@gmail.com>
Co-authored-by: jrhee17 <guins_j@guins.org>
Dogacel pushed a commit to Dogacel/armeria that referenced this pull request Jun 8, 2024
Motivation:

- A user can't use custom JSON marshaller for unframed grpc error.

Modifications:

- Implement `UnframedGrpcErrorHandlerBuilder` which takes a custom json
marshaller

Result:

- Closes line#4723.
- A user can use their custom JSON marshaller for unframed grpc error.
Dogacel pushed a commit to Dogacel/armeria that referenced this pull request Jun 8, 2024
Motivation:

Refactor `UnframedGrpcErrorHandlers`.
line#5555 (comment)

Modifications:

- Create `TextUnframedGrpcErrorHandler` for a plaintext format response.
- Create `JsonUnframedGrpcErrorHandler` for a JSON format response.
- Create `DefaultUnframedGrpcErrorHandler` for a default error handler.

Result:

- Seperate `UnframedGrpcErrorHandlers` into three classes,
`TextUnframedGrpcErrorHandler`, `JsonUnframedGrpcErrorHandler` and
`DefaultUnframedGrpcErrorHandler`.

---------

Co-authored-by: minwoox <songmw725@gmail.com>
Co-authored-by: jrhee17 <guins_j@guins.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature sprint Issues for OSS Sprint participants
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom JSON marshaller for error details in unframed grpc error
4 participants