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

Getting 'TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined' on tail.unwatch()

Open lankesh opened this issue 4 years ago • 0 comments

Here's stack trace:

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
    at makeCallback (fs.js:168:11)
    at Object.close (fs.js:427:14)
    at Tail.unwatch (/home/komal/projects/zestl/source_code/TwigMeServerApplication/docker/clients/python_error_logs/api/node_modules/always-tail/index.js:164:10)
    at Socket.<anonymous> (/home/komal/projects/zestl/source_code/TwigMeServerApplication/docker/clients/python_error_logs/api/services/tail_file.js:22:14)
    at Socket.emit (events.js:327:22)
    at TCP.<anonymous> (net.js:673:12) {
code: 'ERR_INVALID_CALLBACK'
}

Here's what I was trying to do

const TailFile = (req, res, next, filename) => {
    var Tail = require('always-tail');
    var fs   = require('fs');
    if (!fs.existsSync(filename)) {
        fs.writeFileSync(filename, "")
    };
    var tail = new Tail(filename, '\n');
    tail.on('line', function (data) {
        console.log("got line:", data);
        res.write(data)
    });
    tail.on('error', function (data) {
        console.log("error:", data);
    });
    tail.watch();

    res.header('Content-Type', 'text/event-stream');

    req.socket.on('close', () => {
        // This is not working
        tail.unwatch();
    });
};

I am getting error on tail.unwatch();

I wandered around the always-tail code and found that by changing following lines in always-tail/index.js's Tail.prototype.unwatch function, the error message is gone and my application stops crashing Previous code fs.close(self.fd); Fixed code fs.close(self.fd, function(){});

Previous code fs.close(item.fd); Fixed code fs.close(item.fd, function(){});

lankesh avatar Mar 24 '21 11:03 lankesh