Skip to content

Crash on end() #19

Description

@Dagrut

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions