node-death icon indicating copy to clipboard operation
node-death copied to clipboard

Fails with piping

Open dandv opened this issue 8 years ago • 1 comments

$ node script.js | tee script.log
^Cevents.js:163
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at exports._errnoException (util.js:1050:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:814:14)

The script is:

var ON_DEATH = require('death'); //this is intentionally ugly

ON_DEATH(function(signal, err) { console.log('croak'); })

setTimeout(function () {}, 10000);

node-cleanup doesn't call my handler either, but at least doesn't display this ugly error message :)

dandv avatar Jul 19 '17 09:07 dandv

You can use my package, it's more flexible because you have to set what you want to handle and I made it with Docker, PM2, etc in mind.

https://github.com/LuKks/like-process

const like = require('like-process');

like.on('cleanup', () => {
  console.log('croak');
});
like.handle('exit');

setTimeout(function () {}, 10000);

Depending on the use, you should handle more events like uncaughtException:

like.handle(['uncaughtException', 'unhandledRejection', 'exit']);

I'm very available if you have any problem with like-process, I know this issue is extremely old but it's never late for new people that are having the same issue.

LuKks avatar Oct 21 '20 01:10 LuKks