Skip to content
Browse files

Fix #2507 Raise errors less agressively when destroying stdio streams

Also, if an error is already provided, then raise the provided
error, rather than throwing it with a less helpful 'stdout cannot
be closed' message.

This is important for properly handling EPIPEs.
  • Loading branch information...
1 parent a0119af commit 40f8d5570f064f8d232cb6a72e0309e7ef751454 @isaacs committed Jan 26, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/node.js
View
10 src/node.js
@@ -280,17 +280,19 @@
process.__defineGetter__('stdout', function() {
if (stdout) return stdout;
stdout = createWritableStdioStream(1);
- stdout.end = stdout.destroy = stdout.destroySoon = function() {
- throw new Error('process.stdout cannot be closed');
+ stdout.destroy = stdout.destroySoon = function(er) {
+ er = er || new Error('process.stdout cannot be closed.');
+ stdout.emit('error', er);
};
return stdout;
});
process.__defineGetter__('stderr', function() {
if (stderr) return stderr;
stderr = createWritableStdioStream(2);
- stderr.end = stderr.destroy = stderr.destroySoon = function() {
- throw new Error('process.stderr cannot be closed');
+ stderr.destroy = stderr.destroySoon = function(er) {
+ er = er || new Error('process.stderr cannot be closed.');
+ stderr.emit('error', er);
};
return stderr;
});

0 comments on commit 40f8d55

Please sign in to comment.
Something went wrong with that request. Please try again.