Skip to content

Commit 13324bf

Browse files
author
Igor Zinkovsky
committed
throw from stdout.end and stderr.end
1 parent 09329e7 commit 13324bf

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

lib/stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Stream.prototype.pipe = function(dest, options) {
5454
// If the 'end' option is not supplied, dest.end() will be called when
5555
// source gets the 'end' or 'close' events. Only dest.end() once, and
5656
// only when all sources have ended.
57-
if (!options || options.end !== false) {
57+
if (!dest._isStdio && (!options || options.end !== false)) {
5858
dest._pipeCount = dest._pipeCount || 0;
5959
dest._pipeCount++;
6060

src/node.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@
269269
// For supporting legacy API we put the FD here.
270270
stream.fd = fd;
271271

272+
stream._isStdio = true;
273+
272274
return stream;
273275
}
274276

@@ -278,14 +280,18 @@
278280
process.__defineGetter__('stdout', function() {
279281
if (stdout) return stdout;
280282
stdout = createWritableStdioStream(1);
281-
stdout.end = stdout.destroy = stdout.destroySoon = function() { };
283+
stdout.end = stdout.destroy = stdout.destroySoon = function() {
284+
throw new Error('process.stdout cannot be closed');
285+
};
282286
return stdout;
283287
});
284288

285289
process.__defineGetter__('stderr', function() {
286290
if (stderr) return stderr;
287291
stderr = createWritableStdioStream(2);
288-
stderr.end = stderr.destroy = stderr.destroySoon = function() { };
292+
stderr.end = stderr.destroy = stderr.destroySoon = function() {
293+
throw new Error('process.stderr cannot be closed');
294+
};
289295
return stderr;
290296
});
291297

test/simple/test-tty-stdout-end.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
// Can't test this when 'make test' doesn't assign a tty to the stdout.
2323
var common = require('../common');
2424
var assert = require('assert');
25-
var tty = require('tty');
2625

27-
var closed = false;
28-
process.stdout.on('close', function() {
29-
closed = true;
30-
});
31-
process.on('exit', function() {
32-
assert.ok(closed);
33-
});
26+
var exceptionCaught = false;
3427

35-
process.stdout.end();
28+
try {
29+
process.stdout.end();
30+
} catch(e) {
31+
exceptionCaught = true;
32+
assert.ok(common.isError(e));
33+
assert.equal('process.stdout cannot be closed', e.message);
34+
}
35+
36+
assert.ok(exceptionCaught);

0 commit comments

Comments
 (0)