nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] File watcher swallows the first chokidar error and the second one crashes the daemon

Open addyCooks opened this issue 2 weeks ago • 1 comments

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

  1. Create a FileWatcherSource with a fake chokidar-like EventEmitter through the _watchFn option and emit ready.
  2. Check fake.listenerCount('error') after start: it is 1.
  3. fake.emit('error', new Error('ENOSPC first')), then fake.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: after ready, register watcher.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).

addyCooks avatar Nov 14 '26 06:11 addyCooks

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.

Purv-Kabaria avatar Nov 14 '26 10:11 Purv-Kabaria