Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

mskec
Copy link
Contributor

@mskec mskec commented Feb 13, 2017

Migrate console.js to use internal/errors.js.

Refs: #11273

cc @jasnell

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

@nodejs-github-bot nodejs-github-bot added console Issues and PRs related to the console subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Feb 13, 2017
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');
Copy link
Member

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

@@ -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}`);
Copy link
Member

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$/);
Copy link
Member

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.

@mskec
Copy link
Contributor Author

mskec commented Feb 13, 2017

Thank you for feedback.
Should I add error to docs? documenting new errors

@jasnell
Copy link
Member

jasnell commented Feb 14, 2017

Yes, please add it to the docs using the pattern seen in the other PRs #11273

@joyeecheung
Copy link
Member

This looks like a duplicate of #11308, I've added that one to the tracking issue because that one is earlier.

@mskec
Copy link
Contributor Author

mskec commented Feb 14, 2017

@joyeecheung yes unfortunately I didn't see it before I started.
I think this PR is done now, but you decide which one you want.

@joyeecheung joyeecheung added the semver-major PRs that contain breaking changes and should be released in the next major version. label Feb 14, 2017
@jasnell jasnell added the blocked PRs that are blocked by other issues or PRs. label Apr 5, 2017
@fhinkel
Copy link
Member

fhinkel commented May 23, 2017

@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!

@mskec mskec force-pushed the errors-console branch from 622c6b4 to 9ef8396 Compare May 23, 2017 23:06
@mskec
Copy link
Contributor Author

mskec commented May 24, 2017

@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}`);
Copy link
Member

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?

Copy link
Contributor Author

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

@jasnell
Copy link
Member

jasnell commented May 25, 2017

@fhinkel
Copy link
Member

fhinkel commented May 27, 2017

Thanks. Landed in 0ecdf29.

@fhinkel fhinkel closed this May 27, 2017
fhinkel pushed a commit that referenced this pull request May 27, 2017
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]>
@Trott Trott removed the blocked PRs that are blocked by other issues or PRs. label Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants