Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
throw from stdout.end and stderr.end
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Nov 10, 2011
1 parent 09329e7 commit 13324bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/stream.js
Expand Up @@ -54,7 +54,7 @@ Stream.prototype.pipe = function(dest, options) {
// If the 'end' option is not supplied, dest.end() will be called when
// source gets the 'end' or 'close' events. Only dest.end() once, and
// only when all sources have ended.
if (!options || options.end !== false) {
if (!dest._isStdio && (!options || options.end !== false)) {
dest._pipeCount = dest._pipeCount || 0;
dest._pipeCount++;

Expand Down
10 changes: 8 additions & 2 deletions src/node.js
Expand Up @@ -269,6 +269,8 @@
// For supporting legacy API we put the FD here.
stream.fd = fd;

stream._isStdio = true;

return stream;
}

Expand All @@ -278,14 +280,18 @@
process.__defineGetter__('stdout', function() {
if (stdout) return stdout;
stdout = createWritableStdioStream(1);
stdout.end = stdout.destroy = stdout.destroySoon = function() { };
stdout.end = stdout.destroy = stdout.destroySoon = function() {
throw new Error('process.stdout cannot be closed');
};
return stdout;
});

process.__defineGetter__('stderr', function() {
if (stderr) return stderr;
stderr = createWritableStdioStream(2);
stderr.end = stderr.destroy = stderr.destroySoon = function() { };
stderr.end = stderr.destroy = stderr.destroySoon = function() {
throw new Error('process.stderr cannot be closed');
};
return stderr;
});

Expand Down
19 changes: 10 additions & 9 deletions test/simple/test-tty-stdout-end.js
Expand Up @@ -22,14 +22,15 @@
// Can't test this when 'make test' doesn't assign a tty to the stdout.
var common = require('../common');
var assert = require('assert');
var tty = require('tty');

var closed = false;
process.stdout.on('close', function() {
closed = true;
});
process.on('exit', function() {
assert.ok(closed);
});
var exceptionCaught = false;

process.stdout.end();
try {
process.stdout.end();
} catch(e) {
exceptionCaught = true;
assert.ok(common.isError(e));
assert.equal('process.stdout cannot be closed', e.message);
}

assert.ok(exceptionCaught);

1 comment on commit 13324bf

@bnoordhuis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igorzi: This commit seems to have introduced a regression. #2507 is the bug report.

Please sign in to comment.