Skip to content

Replace unwrap() with ? in control_db for proper error propagation#4575

Open
Shiven0504 wants to merge 2 commits intoclockworklabs:masterfrom
Shiven0504:fix/unwrap-and-help-text-in-standalone
Open

Replace unwrap() with ? in control_db for proper error propagation#4575
Shiven0504 wants to merge 2 commits intoclockworklabs:masterfrom
Shiven0504:fix/unwrap-and-help-text-in-standalone

Conversation

@Shiven0504
Copy link
Contributor

@Shiven0504 Shiven0504 commented Mar 6, 2026

Summary

  • Replace 5 unwrap() calls in control_db.rs with ? to propagate errors instead of panicking at runtime (bsatn::to_vec, bsatn::from_slice, and get_replicas)
  • Change get_leader_replica_by_database return type from Option<Replica> to Result<Option<Replica>> across the ControlStateDelegate trait and all implementations/call sites
  • Fix help text for --listen-addr: duplicate word ("to to") and incorrect default port (said 80, actual default is 3000)

Details

The unwrap() calls in control_db.rs could cause panics if serialization/deserialization ever failed. Since all the containing functions already return Result, replacing with ? is straightforward and lets callers handle errors gracefully.

The get_leader_replica_by_database method was the only replica-related method on the trait that didn't return Result, despite calling get_replicas() which can fail. This inconsistency was masked by the unwrap().

Files changed

File Change
crates/standalone/src/control_db.rs Replace 5 unwrap()?, change return type
crates/client-api/src/lib.rs Update trait definition + blanket impl
crates/standalone/src/lib.rs Update trait impl + call site
crates/client-api/src/routes/database.rs Handle new Result at call site
crates/testing/src/modules.rs Handle new Result in test helper
crates/standalone/src/subcommands/start.rs Fix help text typo

Test plan

  • CI compilation and tests should pass — no logic changes, only error propagation
  • The get_leader_replica_by_database callers all handle the new Result appropriately

Shiven0504 and others added 2 commits March 6, 2026 13:56
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant