lucagrulla / node-tail

The zero dependency Node.js module for tailing a file
https://www.lucagrulla.com/node-tail/
MIT License
467 stars 75 forks source link

Uncatchable error #143

Closed chriskinsman closed 2 years ago

chriskinsman commented 2 years ago

I am trying to tail a log file that is sometimes cleaned up before I can tail it.

The issue is that watchEvent throws an error instead of catching the error and doing a this.emit("error", Some message);

Stacktrace in my case:

Error: ENOENT: no such file or directory, stat '/var/log/containers/613951f8c7af69360097cc72-6154f6f8b087f6194793faa5-r7lzd_tilloo-jobs_613951f8c7af69360097cc72-6154f6f8b087f6194793faa5-c2e9662d7234f5f0ead7a27fc56dbf9166b8936dc00237669edc5e283fa757ef.log' at Object.statSync (fs.js:1131:3) at Tail.latestPosition (/tilloo/node_modules/tail/lib/tail.js:81:23) at Tail.change (/tilloo/node_modules/tail/lib/tail.js:125:22) at Tail.watchEvent (/tilloo/node_modules/tail/lib/tail.js:188:18) at FSWatcher. (/tilloo/node_modules/tail/lib/tail.js:149:97) at FSWatcher.emit (events.js:400:28) at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:211:12) { errno: -2, syscall: 'stat', code: 'ENOENT', path: '/var/log/containers/613951f8c7af69360097cc72-6154f6f8b087f6194793faa5-r7lzd_tilloo-jobs_613951f8c7af69360097cc72-6154f6f8b087f6194793faa5-c2e9662d7234f5f0ead7a27fc56dbf9166b8936dc00237669edc5e283fa757ef.log'

Seems like watchEvent should have a try/catch that emits an error when an issue arises.

Because this uncatchable error is raised I am having my process terminate and there is no way for me to catch the error myself.

chriskinsman commented 2 years ago

Pull request #147 to fix

chriskinsman commented 2 years ago

@lucagrulla just bringing to your attention. Thanks!

lucagrulla commented 2 years ago

Fixed with v2.2.4