Replace unwrap() with ? in control_db for proper error propagation#4575
Open
Shiven0504 wants to merge 2 commits intoclockworklabs:masterfrom
Open
Replace unwrap() with ? in control_db for proper error propagation#4575Shiven0504 wants to merge 2 commits intoclockworklabs:masterfrom
Shiven0504 wants to merge 2 commits intoclockworklabs:masterfrom
Conversation
- Replace 5 unwrap() calls in control_db.rs with ? to properly propagate errors instead of panicking at runtime - Change get_leader_replica_by_database return type from Option<Replica> to Result<Option<Replica>> across the trait and all implementations - Fix duplicate "to" and incorrect port number in listen_addr help text Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
unwrap()calls incontrol_db.rswith?to propagate errors instead of panicking at runtime (bsatn::to_vec,bsatn::from_slice, andget_replicas)get_leader_replica_by_databasereturn type fromOption<Replica>toResult<Option<Replica>>across theControlStateDelegatetrait and all implementations/call sites--listen-addr: duplicate word ("to to") and incorrect default port (said 80, actual default is 3000)Details
The
unwrap()calls incontrol_db.rscould cause panics if serialization/deserialization ever failed. Since all the containing functions already returnResult, replacing with?is straightforward and lets callers handle errors gracefully.The
get_leader_replica_by_databasemethod was the only replica-related method on the trait that didn't returnResult, despite callingget_replicas()which can fail. This inconsistency was masked by theunwrap().Files changed
crates/standalone/src/control_db.rsunwrap()→?, change return typecrates/client-api/src/lib.rscrates/standalone/src/lib.rscrates/client-api/src/routes/database.rsResultat call sitecrates/testing/src/modules.rsResultin test helpercrates/standalone/src/subcommands/start.rsTest plan
get_leader_replica_by_databasecallers all handle the newResultappropriately