fix(tui): harden file-watcher against vanished-path ENOENT errors#796
Draft
posthog[bot] wants to merge 2 commits into
Draft
fix(tui): harden file-watcher against vanished-path ENOENT errors#796posthog[bot] wants to merge 2 commits into
posthog[bot] wants to merge 2 commits into
Conversation
startFileWatcher schedules three long-lived callbacks (poll setInterval, fs.watch change listener, attach-retry setInterval) that stat/access the watched path. When the path's directory disappears out from under them, the fs.watch watchers had no 'error' listener, so a watcher error surfaced as an uncaught ENOENT, and already-scheduled callbacks could run after teardown. - Attach an 'error' handler to every fs.watch watcher (via attachWatch) so a vanished path can't raise an unhandled error event. - Add a stopped flag guarding read() and the attach-retry loop so callbacks scheduled before stop() become no-ops after teardown. - Guard w.close() in stop() against double-close. - Tighten the test teardown to stop the watcher and yield before removing the temp dir, and add a regression test for the fs.watch error-event path. Generated-By: PostHog Code Task-Id: 2a9a5b2b-5927-4eab-8fa9-af9c7fae3e57
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
Generated-By: PostHog Code Task-Id: 2a9a5b2b-5927-4eab-8fa9-af9c7fae3e57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The wizard's file-watcher hook (
src/ui/tui/hooks/file-watcher.ts) raised unhandled ENOENT errors when the watched file's directory disappeared out from under its scheduled callbacks.startFileWatcherschedules three long-lived callbacks — a pollsetInterval, anfs.watchchange listener, and an attach-retrysetInterval— each of which stats/accesses the watched path. Thefs.watchwatchers had no'error'listener, so a watcher error on a vanished path surfaced as an uncaught exception, and already-scheduled callbacks could still fire after teardown.This was recurring noise in the wizard's error tracking, firing entirely from the test suite (
file-watcher.test.ts'safterEachremoves the temp dir right afterstop()) — no production/end-user impact, but it costs triage attention and masks real signals.Why: to stop the recurring test/CI-only ENOENT noise in error tracking without changing watcher behavior.
Changes
'error'handler to everyfs.watchwatcher so a vanished path can't raise an unhandled error event.stoppedflag guardingread()and the attach-retry loop so callbacks scheduled beforestop()become no-ops after teardown.w.close()instop()against double-close.fs.watcherror-event path.Test plan
pnpm test— all 90 test files / 1157 tests pass, including the new regression test.'error'event throws with no listener) and passes with the fix.pnpm buildand lint (eslint) clean.Created with PostHog Code from an inbox report.