Skip to content

fix(wtp add): improve error messages for remove-then-add and composite errors#92

Open
0Delta wants to merge 1 commit intosatococoa:mainfrom
0Delta:fix/add-composite-error-messages
Open

fix(wtp add): improve error messages for remove-then-add and composite errors#92
0Delta wants to merge 1 commit intosatococoa:mainfrom
0Delta:fix/add-composite-error-messages

Conversation

@0Delta
Copy link

@0Delta 0Delta commented Feb 26, 2026

What

  • Collect all applicable 'already exists' errors (path, branch, worktree, multiple remotes) and return them as CompositeWorktreeError
  • Show "Error command:" with the full git command and exit status instead of duplicate Technical sections
  • Deduplicate the solution list and show a single shared "Original error" when multiple errors share the same git error
  • Add E2E test for `wtp remove` followed by `wtp add -b` with the same branch

Why

After `wtp remove `, running `wtp add -b ` fails due to the branch still existing, but the message only said "destination path already exists," which was misleading.

Testing

  • `go tool task test` and `go tool task test-e2e` passed

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved error messages when worktree operations fail with more specific details about the type of conflict (existing worktree, branch, or destination path).
    • Enhanced error reporting to provide clearer guidance for resolving issues.
  • Tests

    • Expanded test coverage for error scenarios and edge cases.

…e errors

- Collect all applicable 'already exists' errors (path, branch, worktree, multiple remotes) and return as CompositeWorktreeError
- Show 'Error command:' with full git command and exit status instead of duplicate Technical sections
- Deduplicate solution list and single shared 'Original error' when multiple errors share same git error
- Add E2E test for wtp remove then wtp add -b same branch
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de2e5d2 and 4e8087e.

📒 Files selected for processing (3)
  • cmd/wtp/add.go
  • cmd/wtp/add_test.go
  • test/e2e/error_test.go

📝 Walkthrough

Walkthrough

This PR refactors error handling in the wtp add command by introducing specialized error types for distinct worktree failure scenarios (existing worktree, branch, or path conflicts) and a composite error type to aggregate multiple errors. Function signatures are updated to provide error analysis with additional context about the repository state.

Changes

Cohort / File(s) Summary
Error Type Definitions & Analysis
cmd/wtp/add.go
Introduced four specific error types (WorktreeAlreadyExistsError, BranchAlreadyExistsError, PathAlreadyExistsError, MultipleBranchesError) and CompositeWorktreeError for aggregating errors. Refactored analyzeGitWorktreeError to accept repository path and branch creation flag, with new helpers to collect and format errors.
Test Coverage
cmd/wtp/add_test.go
Added subcases verifying nil Git error handling in error messages. Updated analyzeGitWorktreeError call sites with new parameters. Introduced TestAnalyzeGitWorktreeError_CollectsAllAlreadyExistsErrors integration test and runGit helper for repository setup.
End-to-End Test
test/e2e/error_test.go
Added AddAfterRemoveShowsBranchAlreadyExists test to verify error messaging when re-adding a previously removed worktree branch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 Through tangled git paths, errors now aligned,
With worktrees and branches of every kind,
Composite clarity, no more cryptic sight,
A rabbit's gift of error messages bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary changes: improving error messages for composite errors and the remove-then-add scenario involving worktree operations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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