Skip to content

fix(monitor): handle deleted worktrees gracefully#234

Merged
gregpriday merged 1 commit intomainfrom
bugfix/issue-233-worktree-monitor-deleted-dirs
Nov 25, 2025
Merged

fix(monitor): handle deleted worktrees gracefully#234
gregpriday merged 1 commit intomainfrom
bugfix/issue-233-worktree-monitor-deleted-dirs

Conversation

@gregpriday
Copy link
Copy Markdown
Owner

Summary

Fix for WorktreeMonitor crashing the display when monitoring deleted worktrees. When worktrees are deleted externally (e.g., during automated PR merges), the monitor now gracefully stops polling and emits a removal event instead of flooding stderr with errors.

Closes #233

Changes Made

  • Add WorktreeRemovedError class for distinguishing deleted worktrees from other git errors
  • Add directory existence check in getWorktreeChangesWithStats() before calling simpleGit()
  • Handle WorktreeRemovedError in WorktreeMonitor.updateGitStatus() to stop polling and emit sys:worktree:remove event
  • Add comprehensive tests for deleted worktree scenarios

Implementation Notes

Context & rationale:

  • When worktrees are deleted externally (e.g., during automated PR merges), WorktreeMonitor continued polling them, causing simple-git to throw errors that flooded stderr and destroyed the terminal display
  • Added proactive directory existence check before calling simpleGit(cwd) to catch ENOENT early
  • Created dedicated WorktreeRemovedError class for clear error differentiation
  • Monitor now gracefully stops and emits removal event so UI can clean up

Implementation details:

  • Added WorktreeRemovedError class in src/utils/errorTypes.ts - extends GitError with path context
  • Added fs.access() check in getWorktreeChangesWithStats() before simpleGit() call
  • Added error handling in WorktreeMonitor.updateGitStatus() that detects WorktreeRemovedError, emits sys:worktree:remove, and calls stop()
  • Added comprehensive tests for both the git utility and WorktreeMonitor

Breaking Changes

None - internal resilience improvement

- Add WorktreeRemovedError class for distinguishing deleted worktrees
- Add directory existence check in getWorktreeChangesWithStats before simpleGit
- Handle WorktreeRemovedError in WorktreeMonitor to stop polling and emit removal event
- Add comprehensive tests for deleted worktree scenarios
@gregpriday gregpriday merged commit 78b6e9b into main Nov 25, 2025
@gregpriday gregpriday deleted the bugfix/issue-233-worktree-monitor-deleted-dirs branch November 25, 2025 18:10
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.

WorktreeMonitor crashes display when monitoring deleted worktrees

1 participant