-
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, readline: migrate to use internal/errors.js #11390
errors, readline: migrate to use internal/errors.js #11390
Conversation
lib/readline.js
Outdated
@@ -66,7 +67,7 @@ function Interface(input, output, completer, terminal) { | |||
if (typeof historySize !== 'number' || | |||
isNaN(historySize) || | |||
historySize < 0) { | |||
throw new TypeError('Argument "historySize" must be a positive number'); | |||
throw new errors.TypeError('ERR_NON_NEGATIVE_NUMBER'); |
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 think this is actually a RangeError
? This looks like a ERR_INVALID_OPT_VALUE
to me (refs: https://github.com/nodejs/node/pull/11300/files) too, but we can also make the message format of ERR_NON_NEGATIVE_NUMBER
a function taking description of the variable that's negative, so we can keep the "historySize" part.
On another note, if we want to keep it as a ERR_NON_NEGATIVE_NUMBER
, that code is missing documentation.
lib/readline.js
Outdated
@@ -56,7 +57,7 @@ function Interface(input, output, completer, terminal) { | |||
} | |||
|
|||
if (completer && typeof completer !== 'function') { | |||
throw new TypeError('Argument "completer" must be a function'); | |||
throw new errors.TypeError('ERR_INVALID_CALLBACK'); |
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.
the original message contains useful information(Argument "completer"
), this looks like a ERR_INVALID_OPT_VALUE
to me (refs: https://github.com/nodejs/node/pull/11300/files), passing the completer
as an actual argument is not documented(refs: readline.createInterface()) so it doesn't fit the description of a Node.js style "callback" I think.
@slammayjammay Thanks so much for putting this together. Sorry that it is dragging out for so long due to being a semver-major change. Do you want to address the comments and rebase? Thanks! |
@fhinkel Whoops, forgot about this! Sure, I'll find some time this week to address the feedback. |
049eaf2
to
c4b4497
Compare
doc/api/errors.md
Outdated
@@ -559,7 +559,6 @@ found [here][online]. | |||
encountered by [`http`][] or [`net`][] -- often a sign that a `socket.end()` | |||
was not properly called. | |||
|
|||
|
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.
Accidental whitespace change?
lib/internal/errors.js
Outdated
@@ -114,6 +114,7 @@ E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); | |||
E('ERR_ASSERTION', (msg) => msg); | |||
E('ERR_INVALID_ARG_TYPE', invalidArgType); | |||
E('ERR_INVALID_CALLBACK', 'callback must be a function'); | |||
E('ERR_INVALID_CURSOR_POS', 'Can\'t set cursor row without setting its column'); |
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.
Would be great to avoid using contractions in the error messages.
E('ERR_INVALID_CURSOR_POS',
'Cannot set cursor row without setting its column');
3fd0414
to
3a81d13
Compare
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.
LGTM
@slammayjammay looks good, but unfortunately needs a rebase. |
Makes use of `ERR_INVALID_OPT_VALUE` and removes an unused error code.
dac7cb0
to
4041b97
Compare
PR-URL: #11390 Ref: #11273 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
Landed in 7f3f72c |
Migrate lib/readline.js to use internal/errors.js.
Refs: #11273
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
errors, readline