[Bug] File watcher swallows the first chokidar error and the second one crashes the daemon
Description
After startup the file watcher only has a once('error') listener left over from the startup promise. The first runtime error (for example ENOSPC or EMFILE) is swallowed silently and the second is an unhandled error event that throws.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at f92cce9c)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Create a
FileWatcherSourcewith a fake chokidar-likeEventEmitterthrough the_watchFnoption and emitready. - Check
fake.listenerCount('error')after start: it is 1. fake.emit('error', new Error('ENOSPC first')), thenfake.emit('error', new Error('ENOSPC second')).
Expected Behavior
Every runtime error is logged (and optionally surfaced). The daemon keeps running.
Actual Behavior
The first error is silent. The second one throws.
Logs/Screenshots
error listeners after ready: 1
first error: swallowed silently (no log)
second error: THROWS (unhandled error event): ENOSPC second
Note: I used a fake EventEmitter watcher, not a real inotify limit. chokidar uses the same EventEmitter contract.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/events/sources/file-watcher.ts:49-54: afterready, registerwatcher.on('error', handler)that logs the error, and drop the startup-only listener.- Add a test that emits several errors after
ready.
Related: #548 / PR #553 (startup error only).
I will pick this up, following the suggested listener fix. I will keep startup errors rejecting start(), remove startup-only listeners once ready, and log repeated runtime errors through a persistent listener, with regression coverage.