refactor: add ensure_not_started() guard#466
Conversation
Add a state guard that returns an error if a manager's sync has already been started, and use it in `start_sync()` implementations instead of inline state checks.
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughChanges enhance sync error handling by refactoring SyncError::SyncInProgress to carry a ManagerIdentifier and consolidating duplicate inline state guards across multiple sync manager implementations into a centralized ensure_not_started helper function. This improves error specificity and reduces code duplication. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
| tracing::warn!("{} sync already started.", self.identifier()); | ||
| return Ok(vec![]); | ||
| } | ||
| ensure_not_started(self.state(), self.identifier())?; |
There was a problem hiding this comment.
I think this is bad practice, we are checking this in runtime when we can do it compile time using TypeStatePattern, are you familiar with it??
There was a problem hiding this comment.
This just moves to logic into a function but if you think you can apply the pattern here, feel free to go ahead in a follow up PR :)
Add a state guard that returns an error if a manager's sync has already been started, and use it in
start_sync()implementations instead of inline state checks.Summary by CodeRabbit
Release Notes