EPIPE Bomb
By default, node throws EPIPE
errors if process.stdout
is being written to and
a user runs it through a pipe that gets closed while the process is still outputting
(eg, the simple case of piping a node app through head
).
This seemed a little overzealous to me, so I wrote this to suppress such errors.
Before
example.js
for (var i = 0; i < 100; i++) console.log(i)
Oh the humanity
$ node example.js | head -1
0
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: write EPIPE
at errnoException (net.js:670:11)
at Object.afterWrite [as oncomplete] (net.js:503:19)
After
example.js
require('epipebomb')()
for (var i = 0; i < 100; i++) console.log(i)
Oh the joy!
$ node example.js | head -1
0
Notes
Only the EPIPE
error is captured on process.stdout
- all other errors are thrown as per usual.