Skip to content

[ISSUE #767]🔥Refactor all error handling🚀#772

Merged
mxsm merged 4 commits intomainfrom
en-767
Jul 13, 2024
Merged

[ISSUE #767]🔥Refactor all error handling🚀#772
mxsm merged 4 commits intomainfrom
en-767

Conversation

@mxsm
Copy link
Copy Markdown
Owner

@mxsm mxsm commented Jul 13, 2024

Which Issue(s) This PR Fixes(Closes)

Fixes #767

Brief Description

How Did You Test This Change?

Summary by CodeRabbit

  • Refactor

    • Unified error handling across the project by renaming various error types to a general Error.
    • Simplified method signatures and return types for consistency and clarity.
  • Chores

    • Updated logging from log::info to tracing::info for better tracing capabilities.
    • Added tracing dependency alongside tokio.
  • New Features

    • Introduced platform-specific signal handling for Unix and Windows, including a new function wait_for_signal() to handle SIGINT and SIGTERM signals using tokio.

@mxsm
Copy link
Copy Markdown
Owner Author

mxsm commented Jul 13, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 13, 2024

Walkthrough

The recent changes primarily aim to unify error handling across the RocketMQ project by renaming multiple error types to a generalized Error type. This involves modifying return types, struct definitions, and import statements. Additionally, the changes introduce enhanced signal handling for different platforms and replace the logging library log with tracing.

Changes

Files/Modules Change Summaries
rocketmq-common/src/error.rs Renamed SerdeJsonError enum to Error
rocketmq-common/src/utils/serde_json_utils.rs Updated SerdeJsonUtils struct to use Error
rocketmq-remoting/src/clients.rs Renamed RemotingError to Error in import and method returns
rocketmq-remoting/src/clients/rocketmq_default_impl.rs Updated method return types to use Error
rocketmq-remoting/src/code/broker_request_code.rs Renamed RemotingError enum to Error
rocketmq-remoting/src/codec/remoting_command_codec.rs Replaced specific error types with Error
rocketmq-remoting/src/error.rs Converted specific error structs into variants within Error
rocketmq-remoting/src/lib.rs Introduced type alias Result<T, E = Error>
rocketmq-remoting/src/protocol.rs Updated return types to use Error
rocketmq-remoting/src/protocol/rocketmq_serializable.rs Adjusted return types to use Error
rocketmq-remoting/src/rpc/rpc_client.rs Refactored RpcClientLocal to remove RpcException
rocketmq-remoting/src/rpc/rpc_client_hook.rs Removed import of RpcException
rocketmq-remoting/src/rpc/rpc_client_impl.rs Removed RpcException from method signatures
rocketmq-remoting/src/rpc/rpc_client_utils.rs Modified set_remark_ref method
rocketmq-remoting/src/rpc/rpc_response.rs Updated RpcResponse struct to use Error
rocketmq-store/src/message_store/default_message_store.rs Replaced log with tracing for logging information
rocketmq/Cargo.toml Added tracing as a dependency alongside tokio
rocketmq/src/lib.rs Enhanced platform-specific signal handling

Assessment against linked issues

Objective (Issue #767) Addressed Explanation
Refactor error handling across the project
Enhance signal handling for Unix and Windows platforms
Replace the log library with tracing

Poem

In the code's vast, intricate maze,
Errors now share a unified phrase.
With tracing we log, so clear and bright,
Signals handled with grace, day and night.
RocketMQ's paths now streamlined,
A coder's delight, so well-aligned. 🌟


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@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 details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0c99d64 and a04c08b.

Files selected for processing (17)
  • rocketmq-broker/src/lib.rs (1 hunks)
  • rocketmq-common/src/error.rs (1 hunks)
  • rocketmq-common/src/utils/serde_json_utils.rs (4 hunks)
  • rocketmq-remoting/src/clients.rs (2 hunks)
  • rocketmq-remoting/src/clients/rocketmq_default_impl.rs (4 hunks)
  • rocketmq-remoting/src/code/broker_request_code.rs (2 hunks)
  • rocketmq-remoting/src/codec/remoting_command_codec.rs (5 hunks)
  • rocketmq-remoting/src/error.rs (1 hunks)
  • rocketmq-remoting/src/lib.rs (1 hunks)
  • rocketmq-remoting/src/protocol.rs (3 hunks)
  • rocketmq-remoting/src/protocol/rocketmq_serializable.rs (6 hunks)
  • rocketmq-remoting/src/rpc/rpc_client.rs (1 hunks)
  • rocketmq-remoting/src/rpc/rpc_client_hook.rs (1 hunks)
  • rocketmq-remoting/src/rpc/rpc_client_impl.rs (13 hunks)
  • rocketmq-remoting/src/rpc/rpc_client_utils.rs (1 hunks)
  • rocketmq-remoting/src/rpc/rpc_response.rs (2 hunks)
  • rocketmq/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • rocketmq-common/src/error.rs
  • rocketmq-remoting/src/lib.rs
Additional comments not posted (42)
rocketmq-remoting/src/rpc/rpc_client_hook.rs (1)

20-24: LGTM! Refactored error handling.

The changes align with the objective to standardize error handling by using Result.

rocketmq-remoting/src/rpc/rpc_client.rs (1)

21-32: LGTM! Refactored error handling.

The changes align with the objective to standardize error handling by using Result.

rocketmq-broker/src/lib.rs (1)

45-46: LGTM! Refactored error handling.

The changes align with the objective to standardize error handling by using a type alias for Error.

rocketmq/src/lib.rs (2)

23-37: LGTM! Unix signal handling.

The changes introduce proper signal handling for Unix platforms using tokio::signal.


39-43: LGTM! Windows signal handling.

The changes introduce proper signal handling for Windows platforms using tokio::signal.

rocketmq-remoting/src/code/broker_request_code.rs (3)

3-3: LGTM!

The import of Error from crate::error is correct and necessary for the updated error handling.


4-4: LGTM!

The import of FromStrError from crate::error::Error is correct and necessary for the updated error handling.


37-37: LGTM!

The update to use Error in the FromStr implementation is correct and aligns with the refactoring of error handling.

rocketmq-remoting/src/rpc/rpc_client_utils.rs (1)

47-47: LGTM!

The update to set remarks in the RpcResponse using Error is correct and aligns with the refactoring of error handling.

rocketmq-remoting/src/rpc/rpc_response.rs (3)

21-21: LGTM!

The import of Error from crate::error is correct and necessary for the updated error handling.


29-29: LGTM!

The update to the RpcResponse struct to use the new Error enum is correct and aligns with the refactoring of error handling.


59-64: LGTM!

The addition of the new_exception method to the RpcResponse struct is correct and aligns with the refactoring of error handling.

rocketmq-remoting/src/clients.rs (2)

26-26: LGTM!

The import of Error from crate::error is correct and necessary for the updated error handling.


91-91: LGTM!

The update to the invoke_async method signature to use the new Error enum is correct and aligns with the refactoring of error handling.

rocketmq-remoting/src/error.rs (2)

23-49: LGTM! The Error enum definition is well-structured.

The use of the thiserror crate for error handling and the user-friendly error messages for each variant are appropriate.


53-125: LGTM! The unit tests for the Error enum are comprehensive.

The tests cover all the error variants and ensure that the error messages are correctly generated and mapped.

rocketmq-common/src/utils/serde_json_utils.rs (2)

17-68: LGTM! The SerdeJsonUtils methods are well-defined.

The methods for JSON serialization and deserialization are well-defined and use the serde_json crate. The error handling has been appropriately updated to use the Error enum.


Line range hint 161-204: LGTM! The unit tests for the SerdeJsonUtils struct are comprehensive.

The tests cover all the methods in the SerdeJsonUtils struct and ensure that the JSON serialization and deserialization work correctly and that errors are appropriately handled.

rocketmq-remoting/src/codec/remoting_command_codec.rs (3)

Line range hint 63-135: LGTM! The Decoder implementation for RemotingCommandCodec is well-defined.

The logic for decoding a RemotingCommand from a BytesMut buffer is clear and handles various edge cases. The error handling has been appropriately updated to use the Error enum.


Line range hint 139-155: LGTM! The Encoder implementation for RemotingCommandCodec is well-defined.

The logic for encoding a RemotingCommand into a BytesMut buffer is clear and efficient. The error handling has been appropriately updated to use the Error enum.


Line range hint 159-191: LGTM! The unit tests for the RemotingCommandCodec struct are comprehensive.

The tests cover both the Decoder and Encoder implementations and ensure that the encoding and decoding work correctly and that errors are appropriately handled.

rocketmq-remoting/src/clients/rocketmq_default_impl.rs (2)

Line range hint 213-224: LGTM! The invoke_async method is well-defined.

The method handles timeouts and errors appropriately and uses the Error enum for error handling.


237-237: LGTM! The invoke_oneway method is well-defined.

The method handles timeouts and errors appropriately and uses the Error enum for error handling.

rocketmq-remoting/src/protocol/rocketmq_serializable.rs (7)

Line range hint 53-65:
Ensure proper error handling for decoding errors.

The changes correctly use the generalized Error enum for decoding errors. This improves consistency in error handling across the codebase.


71-71: Ensure proper error handling for UTF-8 errors.

The changes correctly use the generalized Error enum for UTF-8 errors. This improves consistency in error handling across the codebase.


Line range hint 210-224:
Ensure proper error handling for decoding errors.

The changes correctly use the generalized Error enum for decoding errors. This improves consistency in error handling across the codebase.


234-234: Ensure proper error handling for map deserialization.

The changes correctly use the generalized Error enum for map deserialization errors. This improves consistency in error handling across the codebase.


Line range hint 363-363:
Ensure proper error handling for deserialization.

The changes correctly use the generalized Error enum for deserialization errors. This improves consistency in error handling across the codebase.


Line range hint 384-384:
Ensure proper error handling for deserialization.

The changes correctly use the generalized Error enum for deserialization errors. This improves consistency in error handling across the codebase.


Line range hint 384-384:
Ensure proper error handling for JSON serialization.

The changes correctly use the generalized Error enum for JSON serialization errors. This improves consistency in error handling across the codebase.

rocketmq-remoting/src/rpc/rpc_client_impl.rs (9)

69-69: Ensure proper error handling for broker address retrieval.

The changes correctly use the generalized Error enum for broker address retrieval errors. This improves consistency in error handling across the codebase.


84-84: Ensure proper error handling for pull message handling.

The changes correctly use the generalized Error enum for pull message handling errors. This improves consistency in error handling across the codebase.


124-124: Ensure proper error handling for getting minimum offset.

The changes correctly use the generalized Error enum for getting minimum offset errors. This improves consistency in error handling across the codebase.


160-160: Ensure proper error handling for getting maximum offset.

The changes correctly use the generalized Error enum for getting maximum offset errors. This improves consistency in error handling across the codebase.


196-196: Ensure proper error handling for search offset.

The changes correctly use the generalized Error enum for search offset errors. This improves consistency in error handling across the codebase.


232-232: Ensure proper error handling for getting earliest message store time.

The changes correctly use the generalized Error enum for getting earliest message store time errors. This improves consistency in error handling across the codebase.


268-268: Ensure proper error handling for querying consumer offset.

The changes correctly use the generalized Error enum for querying consumer offset errors. This improves consistency in error handling across the codebase.


308-308: Ensure proper error handling for updating consumer offset.

The changes correctly use the generalized Error enum for updating consumer offset errors. This improves consistency in error handling across the codebase.


344-344: Ensure proper error handling for common body requests.

The changes correctly use the generalized Error enum for common body request errors. This improves consistency in error handling across the codebase.

rocketmq-remoting/src/protocol.rs (3)

363-363: Ensure proper error handling for deserialization.

The changes correctly use the generalized Error enum for deserialization errors. This improves consistency in error handling across the codebase.


384-384: Ensure proper error handling for deserialization.

The changes correctly use the generalized Error enum for deserialization errors. This improves consistency in error handling across the codebase.


384-384: Ensure proper error handling for JSON serialization.

The changes correctly use the generalized Error enum for JSON serialization errors. This improves consistency in error handling across the codebase.

@mxsm
Copy link
Copy Markdown
Owner Author

mxsm commented Jul 13, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

Copy link
Copy Markdown
Contributor

@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 details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a04c08b and 7212d4e.

Files selected for processing (1)
  • rocketmq/src/lib.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • rocketmq/src/lib.rs

@mxsm
Copy link
Copy Markdown
Owner Author

mxsm commented Jul 13, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

@mxsm
Copy link
Copy Markdown
Owner Author

mxsm commented Jul 13, 2024

🚀Thanks for your contribution🎉. CodeRabbit(AI) will review your code first🔥

Copy link
Copy Markdown
Contributor

@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 details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7212d4e and 3bc935b.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (4)
  • rocketmq-common/src/utils/serde_json_utils.rs (5 hunks)
  • rocketmq-store/src/message_store/default_message_store.rs (2 hunks)
  • rocketmq/Cargo.toml (1 hunks)
  • rocketmq/src/lib.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • rocketmq-store/src/message_store/default_message_store.rs
Files skipped from review as they are similar to previous changes (2)
  • rocketmq-common/src/utils/serde_json_utils.rs
  • rocketmq/src/lib.rs
Additional comments not posted (1)
rocketmq/Cargo.toml (1)

17-17: Addition of tracing dependency approved.

The addition of the tracing dependency aligns with the PR objectives to refactor error handling and logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved PR has approved auto merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement⚡️] Refactor all error handling

2 participants