Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: replace .unwrap()/.expect() with error propagation in Result functions (#1127)

worktrunk-bota675c20084da
diff --git a/src/commands/list/collect/tasks.rs b/src/commands/list/collect/tasks.rs
index 52ec1f34c..3cbcde436 100644
--- a/src/commands/list/collect/tasks.rs
+++ b/src/commands/list/collect/tasks.rs
@@ -368,7 +368,7 @@ impl Task for WorkingTreeDiffTask {
let wt = ctx
.branch_ref
.working_tree(&ctx.repo)
- .expect("WorkingTreeDiffTask requires a worktree");
+ .ok_or_else(|| ctx.error(Self::KIND, &anyhow::anyhow!("requires a worktree")))?;
// Use --no-optional-locks to avoid index lock contention with WorkingTreeConflictsTask's
// `git stash create` which needs the index lock.
@@ -445,7 +445,7 @@ impl Task for WorkingTreeConflictsTask {
let wt = ctx
.branch_ref
.working_tree(&ctx.repo)
- .expect("WorkingTreeConflictsTask requires a worktree");
+ .ok_or_else(|| ctx.error(Self::KIND, &anyhow::anyhow!("requires a worktree")))?;
// Use --no-optional-locks to avoid index lock contention with WorkingTreeDiffTask.
// Both tasks run in parallel, and `git stash create` below needs the index lock.
@@ -516,7 +516,7 @@ impl Task for GitOperationTask {
let wt = ctx
.branch_ref
.working_tree(&ctx.repo)
- .expect("GitOperationTask requires a worktree");
+ .ok_or_else(|| ctx.error(Self::KIND, &anyhow::anyhow!("requires a worktree")))?;
let git_operation = detect_active_git_operation(&wt);
Ok(TaskResult::GitOperation {
item_idx: ctx.item_idx,
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index 7bfd599ce..05029829b 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -904,18 +904,19 @@ impl RemovalDisplayInfo {
return Ok(());
}
- if deletion_mode.should_keep() && self.branch_was_integrated {
- // User kept an integrated branch - show integration info
- let reason = pre_computed_integration.as_ref().unwrap();
- let target = self.integration_target.as_deref().unwrap_or("target");
- let desc = reason.description();
- let symbol = reason.symbol();
- eprintln!(
- "{}",
- hint_message(cformat!(
- "Branch integrated ({desc} <bold>{target}</>, <dim>{symbol}</>); retained with <bright-black>--no-delete-branch</>"
- ))
- );
+ if deletion_mode.should_keep() {
+ if let Some(reason) = pre_computed_integration.as_ref() {
+ // User kept an integrated branch - show integration info
+ let target = self.integration_target.as_deref().unwrap_or("target");
+ let desc = reason.description();
+ let symbol = reason.symbol();
+ eprintln!(
+ "{}",
+ hint_message(cformat!(
+ "Branch integrated ({desc} <bold>{target}</>, <dim>{symbol}</>); retained with <bright-black>--no-delete-branch</>"
+ ))
+ );
+ }
} else if self.show_unmerged_hint
|| (!deletion_mode.should_keep() && !self.branch_was_integrated)
{