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

Fix: serialize exception response #335

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

JoeCqupt
Copy link
Contributor

@JoeCqupt JoeCqupt commented Jan 10, 2024

Why make this change?

https://github.com/sofastack/sofa-bolt/blob/master/src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java#L180

response forgot to serialize

Summary by CodeRabbit

  • Bug Fixes
    • Improved exception handling in RPC requests by adding serialization of responses for exceptions, along with error logging for serialization failures.
  • Tests
    • Added tests to verify the handling of Throwable during response serialization, ensuring robust error management.

@JoeCqupt JoeCqupt changed the title serialize exception response Fix: serialize exception response Jan 10, 2024
@sofastack-cla sofastack-cla bot added the bug Something isn't working label Jan 10, 2024
@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Jan 10, 2024

@chuailiwu PTAL

@OrezzerO @nobodyiam

@OrezzerO
Copy link
Collaborator

@JoeCqupt Great! I will appreciate if you could add a unit test for it.

Copy link

coderabbitai bot commented Apr 1, 2024

Walkthrough

The recent changes involve enhancing the error handling and logging mechanisms within an RPC framework. Specifically, adjustments were made to re-serialize responses in the event of exceptions and to rigorously test the serialization of Throwable responses. This ensures more robust error reporting and handling, improving the framework's reliability and debugging capabilities.

Changes

File Path Change Summary
.../rpc/protocol/RpcRequestProcessor.java Added re-serialization of responses for exception handling and error logging for serialization failures.
.../rpc/serializer/ClassCustomSerializerTest.java Introduced tests for Throwable response serialization, including necessary imports for testing components.

🐰✨
In the realm of code where the data streams flow,
A rabbit hopped in, with changes in tow.
"Let's catch those errors," it said with a grin,
"And log them all neatly, let the debugging begin!"
With tests now in place and exceptions caught tight,
Our rabbit hops off, into the night. 🌙
✨🐰

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@sofastack-cla sofastack-cla bot added size/M and removed size/XS labels Apr 1, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 829be55 and fabfee6.
Files selected for processing (2)
  • src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java (1 hunks)
  • src/test/java/com/alipay/remoting/rpc/serializer/ClassCustomSerializerTest.java (3 hunks)
Additional Context Used
Additional comments not posted (3)
src/main/java/com/alipay/remoting/rpc/protocol/RpcRequestProcessor.java (1)

182-187: The changes to re-serialize the response in case of an exception and log an error if this fails are sensible. It ensures robust error handling by guaranteeing that even error responses are properly serialized before being sent. However, it would be beneficial to add a comment explaining the rationale behind re-serializing the response for future maintainers.

src/test/java/com/alipay/remoting/rpc/serializer/ClassCustomSerializerTest.java (2)

23-28: The added imports for AtomicBoolean, DefaultCustomSerializer, ResponseCommand, InvokeServerException, and RpcServerException are necessary for the new test method and are correctly placed. Good job ensuring that only the required imports are added.


309-346: The testResponseSerialThrowable method is well-implemented, effectively testing the serialization of a response when a Throwable is thrown. The use of AtomicBoolean to track serialization attempts is appropriate. To improve maintainability, consider adding comments explaining the purpose of the test and the significance of each assertion. This will make it easier for future maintainers to understand the test's intent and logic.

@JoeCqupt
Copy link
Contributor Author

JoeCqupt commented Apr 8, 2024

@JoeCqupt Great! I will appreciate if you could add a unit test for it.

done

Copy link
Collaborator

@chuailiwu chuailiwu left a comment

Choose a reason for hiding this comment

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

lgtm

@chuailiwu chuailiwu merged commit cc33824 into sofastack:master Apr 17, 2024
1 check passed
JoeCqupt added a commit to JoeCqupt/sofa-bolt that referenced this pull request Jun 5, 2024
* serialize exception response

* add unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants