lucagrulla / node-tail

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

Event occurs after unwatching file #123

Closed haova closed 3 years ago

haova commented 3 years ago

Hi, I forked a new repository and run a test case. Then this error appeared:

  Tail
    ✓ should read a file with Windows line ending
    ✓ should read a file with Linux line ending
    ✓ should handle null separator option to not split chunks
    ✓ should respect fromBeginning flag (3003ms)
    ✓ should respect fromBeginning from even the first appended line
    ✓ should send error event on deletion of file while watching
    1) should send error event on deletion of file while watching

  6 passing (3s)
  1 failing

  1) Tail
       should send error event on deletion of file while watching:
     Uncaught Error: ENOENT: no such file or directory, stat '/media/anhhao/Data1/Projects/Anh Hao/node-tail/test/example.txt'
      at Object.statSync (fs.js:1086:3)
      at Tail.latestPosition (src/tail.js:74:23)
      at Tail.change (src/tail.js:118:22)
      at Tail.watchEvent (src/tail.js:183:18)
      at FSWatcher.<anonymous> (src/tail.js:143:101)
      at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:186:12)

After a few minutes of research, I detected the problem occur when a change event still emit after unwatching the file.

I'm using Ubuntu 20.04 and saw more problems than this one. Hope to see your fixes in the future soon.

Thanks.

lucagrulla commented 3 years ago

hi @anhhao-me, Thanks for reporting this issue. Two questions: 1) is this a problem purely on running the tests, or have you seen these issue also when running the library in production? 2) "I saw more problems than this one": which other issues have you seen?

lucagrulla commented 3 years ago

Currently tail emits specific error events after unwatch. There's no additional line event after unwatch.