-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
console: check that stderr is writable #5635
Conversation
c4c732a
to
98816bc
Compare
throw new TypeError('Console expects writable stream instances'); | ||
} | ||
|
||
|
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.
extra newline
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.
Fixed. Thanks.
lgtm (I think) |
a3281f8
to
a63bed4
Compare
LGTM |
I know I marked it |
a63bed4
to
5eba8a2
Compare
bump @nodejs/collaborators |
@@ -12,6 +12,10 @@ function Console(stdout, stderr) { | |||
if (!stderr) { | |||
stderr = stdout; | |||
} | |||
if (typeof stderr.write !== 'function') { |
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.
To be more explicit about what's going on, mind putting this in an if else
with the above? Since if stderr == stdout
there's no need to check stderr.write
.
Mind an alternative wording in the first sentence? Something like "Now instead stderr mirrors stdout's check in the constructor." Key change is the explicit reference to the check being in "the constructor". Also, this is a semver-minor change. If this was attempted previously:
Or the alternative is that they hack around and close the fd. Which has poor results:
So there's no reasonable assumption that existing code would rely on existing behavior. Nothing to worry about. (unless, of course, a bad stream was passed to stderr but was never written to, but have a hard time justifying that we guard that case. if it was the case I'd call this a bug fix b/c it allowed users to write invalid code) |
`Console` constructor checks that `stdout.write()` is a function but does not do an equivalent check for `stderr.write()`. If `stderr` is not specified in the constructor, then `stderr` is set to be `stdout`. However, if `stderr` is specified, but `stderr.write()` is not a function, then an exception is not thrown until `console.error()` is called. This change adds the same check for 'stderr' in the constructor that is there for `stdout`. If `stderr` fails the check, then a `TypeError` is thrown. Took the opportunity to copyedit the `console` doc a little too.
5eba8a2
to
d59b431
Compare
@trevnorris I've rebased, fixed things up based on your comments, and force pushed. PTAL |
`Console` constructor checks that `stdout.write()` is a function but does not do an equivalent check for `stderr.write()`. If `stderr` is not specified in the constructor, then `stderr` is set to be `stdout`. However, if `stderr` is specified, but `stderr.write()` is not a function, then an exception is not thrown until `console.error()` is called. This change adds the same check for 'stderr' in the constructor that is there for `stdout`. If `stderr` fails the check, then a `TypeError` is thrown. Took the opportunity to copyedit the `console` doc a little too. PR-URL: nodejs#5635 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
Landed in 6ba5af2 |
`Console` constructor checks that `stdout.write()` is a function but does not do an equivalent check for `stderr.write()`. If `stderr` is not specified in the constructor, then `stderr` is set to be `stdout`. However, if `stderr` is specified, but `stderr.write()` is not a function, then an exception is not thrown until `console.error()` is called. This change adds the same check for 'stderr' in the constructor that is there for `stdout`. If `stderr` fails the check, then a `TypeError` is thrown. Took the opportunity to copyedit the `console` doc a little too. PR-URL: #5635 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
`Console` constructor checks that `stdout.write()` is a function but does not do an equivalent check for `stderr.write()`. If `stderr` is not specified in the constructor, then `stderr` is set to be `stdout`. However, if `stderr` is specified, but `stderr.write()` is not a function, then an exception is not thrown until `console.error()` is called. This change adds the same check for 'stderr' in the constructor that is there for `stdout`. If `stderr` fails the check, then a `TypeError` is thrown. Took the opportunity to copyedit the `console` doc a little too. PR-URL: #5635 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
`Console` constructor checks that `stdout.write()` is a function but does not do an equivalent check for `stderr.write()`. If `stderr` is not specified in the constructor, then `stderr` is set to be `stdout`. However, if `stderr` is specified, but `stderr.write()` is not a function, then an exception is not thrown until `console.error()` is called. This change adds the same check for 'stderr' in the constructor that is there for `stdout`. If `stderr` fails the check, then a `TypeError` is thrown. Took the opportunity to copyedit the `console` doc a little too. PR-URL: #5635 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
console
Description of change
Console
constructor checks thatstdout.write()
is a function butdoes not do an equivalent check for
stderr.write()
. Ifstderr
is notspecified in the constructor, then
stderr
is set to bestdout
.However, if
stderr
is specified, butstderr.write()
is not afunction, then an exception is not thrown until
console.error()
iscalled.
This change mirrors the check already there for
stdout
forstderr
.If
stderr
fails the check, then aTypeError
is thrown.Quite possibly
semver-major
on the grounds that code out there couldbe dependent on the current behavior.
Took the opportunity to copyedit the
console
doc a little too.