-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
errors: migrate lib/console #11340
errors: migrate lib/console #11340
Conversation
lib/console.js
Outdated
const util = require('util'); | ||
|
||
function Console(stdout, stderr) { | ||
if (!(this instanceof Console)) { | ||
return new Console(stdout, stderr); | ||
} | ||
if (!stdout || typeof stdout.write !== 'function') { | ||
throw new TypeError('Console expects a writable stream instance'); | ||
throw new errors.TypeError('ERR_CONSOLE_WRTBLSTRM', 'stdout'); |
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.
I'd say just go ahead and write out WRITABLE_STREAM
instead of abbreviating
lib/internal/errors.js
Outdated
@@ -86,3 +86,5 @@ module.exports = exports = { | |||
// Note: Please try to keep these in alphabetical order | |||
E('ERR_ASSERTION', (msg) => msg); | |||
// Add new errors from here... | |||
|
|||
E('ERR_CONSOLE_WRTBLSTRM', (streamName) => `Console expects a writable stream instance for ${streamName}`); |
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.
Please line wrap at 80 chars
@@ -18,14 +18,14 @@ assert.strictEqual('function', typeof Console); | |||
// when not given a writable stream instance | |||
assert.throws(() => { | |||
new Console(); | |||
}, /^TypeError: Console expects a writable stream instance$/); | |||
}, /^TypeError\[ERR_CONSOLE_WRTBLSTRM\]: Console expects a writable stream instance for stdout$/); |
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.
Please use the new common.expectsError()
method here.
Thank you for feedback. |
Yes, please add it to the docs using the pattern seen in the other PRs #11273 |
This looks like a duplicate of #11308, I've added that one to the tracking issue because that one is earlier. |
@joyeecheung yes unfortunately I didn't see it before I started. |
@mskec Thanks so much for putting this together. Sorry that it is dragging out for so long due to being a semver-major change. Could you rebase and also squash your commits (I think all the changes should be one commit, right?). Thanks! |
@fhinkel I rebased and squashed commits. Let me know if there is anything else |
@@ -112,6 +112,8 @@ module.exports = exports = { | |||
// Note: Please try to keep these in alphabetical order | |||
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); | |||
E('ERR_ASSERTION', (msg) => msg); | |||
E('ERR_CONSOLE_WRITABLE_STREAM', | |||
(name) => `Console expects a writable stream instance for ${name}`); |
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.
Why not use the %s
syntax already used by several other format strings?
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.
No special reason. I made this PR when there was no other error messages using %s
syntax.
Will change if you think that way is better
Thanks. Landed in 0ecdf29. |
Migrate console.js to use internal/errors.js. PR-URL: #11340 Ref: #11273 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Migrate console.js to use internal/errors.js.
Refs: #11273
cc @jasnell
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)