-
Notifications
You must be signed in to change notification settings - Fork 216
[ISSUE #5171]✨Add error handlingor uninitialized DefaultMQProducer in send_to_queue_with_callback_timeout #5366
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
Conversation
…r in send_to_queue_with_callback_timeout
|
🔊@WaterWhisperer 🚀Thanks for your contribution🎉! 💡CodeRabbit(AI) will review your code first🔥! Note 🚨The code review suggestions from CodeRabbit are to be used as a reference only, and the PR submitter can decide whether to make changes based on their own judgment. Ultimately, the project management personnel will conduct the final code review💥. |
WalkthroughThis PR replaces an unsafe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rocketmq-client/src/producer/default_mq_producer.rs (1)
1203-1231: Critical: Test validates the wrong method.This test is named
request_with_callback_not_initializedand callsrequest_with_callback(Line 1222), but the PR actually fixessend_to_queue_with_callback_timeout(Line 787). The test does not verify the fix introduced in this PR, leaving the change untested.🔎 Proposed fix to test the correct method
#[tokio::test] - async fn request_with_callback_not_initialized() { + async fn send_to_queue_with_callback_timeout_not_initialized() { // Arrange let mut producer = DefaultMQProducer { client_config: Default::default(), producer_config: Default::default(), default_mqproducer_impl: None, }; let msg = Message { topic: "test-topic".into(), flag: 0, properties: Default::default(), body: None, compressed_body: None, transaction_id: None, }; let callback = |_msg: Option<&dyn MessageTrait>, _err: Option<&dyn std::error::Error>| { // no-op }; - let result = producer.request_with_callback(msg, callback, 1000).await; + let mq = MessageQueue::default(); + let result = producer.send_to_queue_with_callback_timeout(msg, mq, callback, 1000).await; assert!(result.is_err()); let err = result.unwrap_err(); match err { RocketMQError::NotInitialized(reason) => { assert!(reason.contains("not initialized"), "unexpected error message: {reason}"); } other => panic!("Unexpected error: {other:?}"), } }
🧹 Nitpick comments (1)
rocketmq-client/src/producer/default_mq_producer.rs (1)
798-802: Consider applying the same error handling pattern to remaining methods.While this PR correctly fixes
send_to_queue_with_callback_timeout, many other methods still useunwrap()ondefault_mqproducer_impl.as_mut()and will panic if the producer is uninitialized. For consistency and robustness, consider replacing these with theok_or()pattern used in the fix.Examples of methods still using
unwrap():
- Line 800:
send_oneway_to_queue- Line 948:
send_batch- Line 1015:
send_batch_with_callback- And approximately 15+ other methods throughout the file
This ensures all methods provide clear error messages instead of panicking, improving the overall API ergonomics.
Also applies to: 948-948, 1013-1015
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
rocketmq-client/src/producer/default_mq_producer.rs
🧰 Additional context used
🧬 Code graph analysis (1)
rocketmq-client/src/producer/default_mq_producer.rs (1)
rocketmq-error/src/unified.rs (1)
not_initialized(521-523)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build & Test (windows-latest)
- GitHub Check: Build & Test (macos-latest)
- GitHub Check: Build & Test (ubuntu-latest)
- GitHub Check: Code Coverage
- GitHub Check: auto-approve
🔇 Additional comments (1)
rocketmq-client/src/producer/default_mq_producer.rs (1)
785-787: LGTM! Proper error handling replaces unsafe unwrap.The change correctly replaces the panic-prone
unwrap()with guarded error handling that returns a descriptive error whenDefaultMQProducerImplis uninitialized. This matches the PR objective and is consistent with similar error handling patterns elsewhere in the file.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5366 +/- ##
==========================================
- Coverage 37.17% 37.10% -0.08%
==========================================
Files 800 800
Lines 108077 108308 +231
==========================================
+ Hits 40182 40187 +5
- Misses 67895 68121 +226 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rocketmq-rust-bot
left a comment
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.
LGTM - All CI checks passed ✅
Which Issue(s) This PR Fixes(Closes)
Fixes #5171
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.