-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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, path: migrate to use internal/errors.js #11319
Conversation
lib/path.js
Outdated
|
||
function assertPath(path) { | ||
if (typeof path !== 'string') { | ||
throw new TypeError('Path must be a string. Received ' + inspect(path)); | ||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', 'String'); |
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 typeof path
is not passed?
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 typeof path
was not passed before the change. The inspect(path)
returned the value, this is not something the ERR_INVALID_ARG_TYPE
supports.
Related: #11308 also has an implementation for |
@thefourtheye : yes, it's the same implementation. Just like in #11300 |
967737a
to
9fa0056
Compare
I've just rebased this. |
lib/path.js
Outdated
@@ -816,7 +816,7 @@ const win32 = { | |||
|
|||
basename: function basename(path, ext) { | |||
if (ext !== undefined && typeof ext !== 'string') | |||
throw new TypeError('"ext" argument must be a string'); | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'String'); |
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.
hmm... I'm thinking string
(lowercase) would be better on these.
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
9fa0056
to
a567257
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.
Need to gourd against changes in messages https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#breaking-changes
@@ -16,7 +16,7 @@ assert.throws(function() { | |||
|
|||
assert.throws(function() { | |||
fs.watchFile(new Object(), common.noop); | |||
}, /Path must be a string/); | |||
}, common.expectsError({code: 'ERR_INVALID_ARG_TYPE', type: TypeError})); |
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.
Could you add an assertion on the message as well?
(Changing the message is semver-major
so let's enforce it)
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.
This is a semver-major change, so it's totally fine to change the message.
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.
Yes, but let's keep it from regressing.
const expectedMessage = common.expectsError({ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError | ||
}); |
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.
ditto.
(You can turn this into a Factory that takes the messages)
@@ -372,7 +372,7 @@ function fail(fn) { | |||
|
|||
assert.throws(() => { | |||
fn.apply(null, args); | |||
}, TypeError); | |||
}, common.expectsError({code: 'ERR_INVALID_ARG_TYPE', type: TypeError})); |
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.
Tritto
CI failures are infrastructure related. |
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
{method: 'format', input: [null], message: expectedMessage}, | ||
{method: 'format', input: [''], message: expectedMessage}, | ||
{method: 'format', input: [true], message: expectedMessage}, | ||
{method: 'format', input: [1], message: expectedMessage}, |
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.
We'll need to agree on whether the tests should check the contents of the message or not, but since have landed tests both with and without, I'm fine with landing as is.
@refack I can't quite tell from the comments/discussion if your suggestions have been addressed and you are ok with this landing. It looks like the CI is good and it may be ready to go but I'd like to be sure. Since the CI is also 2 weeks old we probably want to run a new one. |
@mhdawson Like you said, not worth blocking for full message validation. |
@refack thanks for the quick response. I'll open an issue where we can discuss what we think is the right way to go on the messages and then we can do a second pass to fix up based on what we decide. New CI run: https://ci.nodejs.org/job/node-test-pull-request/8517/ |
OSX CI failure looks unrelated. Opened this issue to track: #13507 |
CI good so landing. |
Landed as dcfbbac |
PR-URL: #11319 Ref: #11273 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Migrate path.js to use internal/errors.js.
Refs: #11273
cc @jasnell
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
errors,path