-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process: swallow stdout/stderr error events #9470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,26 +8,64 @@ function setupStdio() { | |
function getStdout() { | ||
if (stdout) return stdout; | ||
stdout = createWritableStdioStream(1); | ||
|
||
Object.defineProperty(stdout._writableState, 'ended', { | ||
set() {}, | ||
get() { | ||
return false; | ||
} | ||
}); | ||
// XXX(Fishrock123): This should work I think, but it causes | ||
// problems with some child-process related tests. | ||
// | ||
// Object.defineProperty(stdout, 'destroyed', { | ||
// set() {}, | ||
// get() { | ||
// return true; | ||
// } | ||
// }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nodejs/streams this affected some other tests but I wasn't able to tell why.
&
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The current patch works, but I think maybe having |
||
|
||
stdout.destroy = stdout.destroySoon = function(er) { | ||
stdout.destroyed = true; | ||
er = er || new Error('process.stdout cannot be closed.'); | ||
stdout.emit('error', er); | ||
}; | ||
if (stdout.isTTY) { | ||
process.on('SIGWINCH', () => stdout._refreshSize()); | ||
} | ||
stdout.on('error', () => {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this is a good idea. If my program writes stdout to a file and that fails, it should definitely not pass silently – if this is about making There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, perhaps. I'd like to have a bit more discussion, I don't know if throwing from stdio on process is a good idea either. There are a lot of libraries that do raw writes that could be affected by e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced that we should do this in the first place. I'm with @addaleax. Even if we land, a comment on why that handler is there is 100% needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another -1. Hiding failure != safety. |
||
return stdout; | ||
} | ||
|
||
function getStderr() { | ||
if (stderr) return stderr; | ||
stderr = createWritableStdioStream(2); | ||
|
||
Object.defineProperty(stderr._writableState, 'ended', { | ||
set() {}, | ||
get() { | ||
return false; | ||
} | ||
}); | ||
// XXX(Fishrock123): This should work I think, but it causes | ||
// problems with some child-process related tests. | ||
// | ||
// Object.defineProperty(stderr, 'destroyed', { | ||
// set() {}, | ||
// get() { | ||
// return true; | ||
// } | ||
// }); | ||
|
||
stderr.destroy = stderr.destroySoon = function(er) { | ||
stderr.destroyed = true; | ||
er = er || new Error('process.stderr cannot be closed.'); | ||
stderr.emit('error', er); | ||
}; | ||
if (stderr.isTTY) { | ||
process.on('SIGWINCH', () => stderr._refreshSize()); | ||
} | ||
stderr.on('error', () => {}); | ||
return stderr; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
'use strict'; | ||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const shouldThrow = function() { | ||
process.stdout.end(); | ||
}; | ||
|
||
const validateError = function(e) { | ||
return e instanceof Error && | ||
e.message === 'process.stdout cannot be closed.'; | ||
}; | ||
|
||
assert.throws(shouldThrow, validateError); | ||
process.stdout.on('error', common.mustCall(function(e) { | ||
assert(e instanceof Error, 'e is an Error'); | ||
assert.strictEqual(e.message, 'process.stdout cannot be closed.'); | ||
})); | ||
process.stdout.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value: true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutually exclusive with getters and still overwritable.