tail-stream icon indicating copy to clipboard operation
tail-stream copied to clipboard

Crash on end()

Open Dagrut opened this issue 7 years ago • 1 comments

Hello,

I met an error with this plugin : When the .end() event is called before the end of the file is reached (and so when the watcher is not started yet), an error happens :

/home/dagrut/myproject/node_modules/tail-stream/index.js:155
            this.watcher.close();
                        ^

TypeError: Cannot read property 'close' of undefined
    at TailStream.end (/home/dagrut/myproject/node_modules/tail-stream/index.js:155:25)

[...]

The problem is here :

    this.end = function(errCode) {
        if(errCode != 'EBADF') {
            fs.close(this.fd);
        }
        this.push(null);
        if(this.watcher === true) {
            fs.unwatchFile(this.path, this.watchFileCallback);
        } else {
            this.watcher.close();
        }
    };

the .close() method is called on watcher, which is undefined when the end of the file was not reached before. Checking for undefined (or using instanceof or typeof) should fix this issue.

I don't have enough time to make a pull request, sorry!

Dagrut avatar Oct 24 '17 07:10 Dagrut

(seems to have been patched?)

shaunc avatar Mar 24 '18 00:03 shaunc