Skip to content

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

Refactor wt list error handling

Maximilian Roosfb385406d51d
diff --git a/.claude/rules/cli-output-formatting.md b/.claude/rules/cli-output-formatting.md
index 758e24911..b8c2a508d 100644
--- a/.claude/rules/cli-output-formatting.md
+++ b/.claude/rules/cli-output-formatting.md
@@ -411,6 +411,34 @@ output::gutter(format_with_gutter(&log, "", None))?;
output::print(progress_message("Merging...\n"))?;
```
+**Avoid bullets in messages:** Use gutter formatting instead of bullet lists
+(`- item`) for multi-line content. Bullets add visual noise and don't provide
+the same clear separation as gutter formatting.
+
+```rust
+// BAD - bullet list in warning
+let mut warning = String::from("Some git operations failed:");
+for error in &errors {
+ warning.push_str(&format!("\n - {}: {}", name, msg));
+}
+output::print(warning_message(warning))?;
+
+// GOOD - gutter formatting with bold branch names
+let error_lines: Vec<String> = errors
+ .iter()
+ .map(|e| cformat!("<bold>{}</>: {}", e.name, e.msg))
+ .collect();
+let warning = format!(
+ "Some git operations failed:\n{}",
+ format_with_gutter(&error_lines.join("\n"), "", None)
+);
+output::print(warning_message(warning))?;
+```
+
+The gutter provides consistent visual structure. Branch names should be bolded
+for emphasis. If we find cases where bullets are genuinely better than gutter
+formatting, we can reconsider this policy.
+
## Error Message Formatting
**Single-line errors with variables are fine:**
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rs
index cbe507a60..456129214 100644
--- a/src/commands/list/collect.rs
+++ b/src/commands/list/collect.rs
@@ -19,11 +19,12 @@
//! - Within worktrees: Git operations (ahead/behind, diffs, CI) run concurrently via scoped threads
//!
//! This ensures fast operations don't wait for slow ones (e.g., CI doesn't block ahead/behind counts)
+use color_print::cformat;
use crossbeam_channel as chan;
use dunce::canonicalize;
use rayon::prelude::*;
use worktrunk::git::{LineDiff, Repository, Worktree};
-use worktrunk::styling::{INFO_EMOJI, warning_message};
+use worktrunk::styling::{INFO_EMOJI, format_with_gutter, warning_message};
use crate::commands::is_worktree_at_expected_path;
@@ -938,15 +939,18 @@ pub fn collect(
if !items_with_missing.is_empty() {
diag.push_str("\nMissing results:");
- for result in &items_with_missing {
- let missing_names: Vec<&str> =
- result.missing_kinds.iter().map(|k| k.into()).collect();
- diag.push_str(&format!(
- "\n - {}: {}",
- result.name,
- missing_names.join(", ")
- ));
- }
+ let missing_lines: Vec<String> = items_with_missing
+ .iter()
+ .map(|result| {
+ let missing_names: Vec<&str> =
+ result.missing_kinds.iter().map(|k| k.into()).collect();
+ cformat!("<bold>{}</>: {}", result.name, missing_names.join(", "))
+ })
+ .collect();
+ diag.push_str(&format!(
+ "\n{}",
+ format_with_gutter(&missing_lines.join("\n"), "", None)
+ ));
}
diag.push_str(
@@ -1007,14 +1011,20 @@ pub fn collect(
if !errors.is_empty() {
// Sort for deterministic output (tasks complete in arbitrary order)
errors.sort_by_key(|e| (e.item_idx, e.kind));
- let mut warning = String::from("Some git operations failed:");
- for error in &errors {
- let name = all_items[error.item_idx].branch_name();
- let kind_str: &'static str = error.kind.into();
- // Take first line only - git errors can be multi-line with usage hints
- let msg = error.message.lines().next().unwrap_or(&error.message);
- warning.push_str(&format!("\n - {}: {} ({})", name, kind_str, msg));
- }
+ let error_lines: Vec<String> = errors
+ .iter()
+ .map(|error| {
+ let name = all_items[error.item_idx].branch_name();
+ let kind_str: &'static str = error.kind.into();
+ // Take first line only - git errors can be multi-line with usage hints
+ let msg = error.message.lines().next().unwrap_or(&error.message);
+ cformat!("<bold>{}</>: {} ({})", name, kind_str, msg)
+ })
+ .collect();
+ let warning = format!(
+ "Some git operations failed:\n{}",
+ format_with_gutter(&error_lines.join("\n"), "", None)
+ );
crate::output::print(warning_message(warning))?;
}
diff --git a/tests/snapshots/integration__integration_tests__list__git_error_warning.snap b/tests/snapshots/integration__integration_tests__list__git_error_warning.snap
index d809fc019..bc384dd50 100644
--- a/tests/snapshots/integration__integration_tests__list__git_error_warning.snap
+++ b/tests/snapshots/integration__integration_tests__list__git_error_warning.snap
@@ -34,8 +34,10 @@ exit_code: 0
⚪ Showing 2 worktrees
🟡 Some git operations failed:
- - feature: commit-details (fatal: bad object 0000000000000000000000000000000000000000)
- - feature: ahead-behind (fatal: Invalid symmetric difference expression main...0000000000000000000000000000000000000000)
- - feature: committed-trees-match (fatal: ambiguous argument '0000000000000000000000000000000000000000^{tree}': unknown revision or path not in the working tree.)
- - feature: has-file-changes (fatal: Invalid symmetric difference expression main...feature)
- - feature: working-tree-diff (fatal: bad object HEAD)
+  feature: commit-details (fatal: bad object 0000000000000000000000000000000000000000)
+  feature: ahead-behind (fatal: Invalid symmetric difference expression main...0000000000000000000000000000000000000000)
+  feature: committed-trees-match (fatal: ambiguous argument '0000000000000000000000000000000000000000^{tree}': unknown revision or path not in the
+  working tree.)
+  feature: has-file-changes (fatal: Invalid symmetric difference expression main...feature)
+  feature: working-tree-diff (fatal: bad object HEAD)
+