-
Notifications
You must be signed in to change notification settings - Fork 30k
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
internal: use internal/errors #13829
Conversation
lib/internal/fs.js
Outdated
@@ -52,7 +53,7 @@ function stringToFlags(flag) { | |||
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL; | |||
} | |||
|
|||
throw new Error('Unknown file open flag: ' + flag); | |||
throw new errors.Error('ERR_INVALID_OPT_VALUE', 'flag', flag); |
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.
Shouldn't these be TypeError
s?
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 agree. X 2
|
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.
Good, but needs a few tweaks
@@ -12,7 +12,7 @@ assert.strictEqual(typeof ChildProcess, 'function'); | |||
[undefined, null, 'foo', 0, 1, NaN, true, false].forEach((options) => { | |||
assert.throws(() => { | |||
child.spawn(options); | |||
}, /^TypeError: "options" must be an object$/); | |||
}, common.expectsError({ code: 'ERR_INVALID_ARG_TYPE' })); |
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.
{type}
should be added.
{message}
would be nice.
lib/internal/util.js
Outdated
@@ -204,14 +204,16 @@ const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs'); | |||
function promisify(orig) { | |||
if (typeof orig !== 'function') { | |||
const errors = require('internal/errors'); | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'original', 'function'); | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'orig', '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.
The other way around (rename the formal parameter) - https://nodejs.org/api/util.html#util_util_promisify_original
lib/internal/fs.js
Outdated
@@ -52,7 +53,7 @@ function stringToFlags(flag) { | |||
case 'xa+': return O_APPEND | O_CREAT | O_RDWR | O_EXCL; | |||
} | |||
|
|||
throw new Error('Unknown file open flag: ' + flag); | |||
throw new errors.Error('ERR_INVALID_OPT_VALUE', 'flag', flag); |
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 agree. X 2
Comments addressed |
Better, but all |
e57cc6e
to
904ad1b
Compare
Addressed and rebased |
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.
💯
Just found #11317. |
@refack I tried to find a duplicate and I didn't find that one... I am fine to remove the overlapping changes here. I guess that would be best? |
Oh, #11317 was closed when I was looking for it. That's why I couldn't find it 😃 |
I don't think flags need a special error code. |
Yep. |
lib/internal/child_process.js
Outdated
@@ -273,22 +276,31 @@ ChildProcess.prototype.spawn = function(options) { | |||
if (options.envPairs === undefined) | |||
options.envPairs = []; | |||
else if (!Array.isArray(options.envPairs)) | |||
throw new TypeError('"envPairs" must be an array'); | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | |||
'options.envPairs', |
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.
nit: these need to be lined up.
lib/internal/util.js
Outdated
@@ -201,17 +201,19 @@ function getConstructorOf(obj) { | |||
const kCustomPromisifiedSymbol = Symbol('util.promisify.custom'); | |||
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs'); | |||
|
|||
function promisify(orig) { | |||
if (typeof orig !== 'function') { | |||
function promisify(original) { |
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 change looks entirely unrelated to the internal/errors change... it should likely be in it's own PR
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.
+1
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 it is pretty much a leftover of a former change. I'll remove it again
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.
}, re); | ||
}, 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.
should go ahead and include the message here too
lib/internal/fs.js
Outdated
@@ -18,7 +19,7 @@ const { | |||
|
|||
function assertEncoding(encoding) { | |||
if (encoding && !Buffer.isEncoding(encoding)) { | |||
throw new Error(`Unknown encoding: ${encoding}`); | |||
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'encoding', encoding); |
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.
Having a specific ERR_UNKNOWN_ENCODING
error would be better here.
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 believe this and the flags
assertion are superseded by #11317
(Where I made the opposite argument 😉 #11317 (comment) )
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 I agree that sticking to the generic one makes sense, but open discussion on the merits of a more specific one.
test/parallel/test-fs-open-flags.js
Outdated
); | ||
}); | ||
|
||
assert.throws( | ||
() => stringToFlags({}), | ||
/^Error: Unknown file open flag: \[object Object\]$/ | ||
common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', 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.
A more specific error here would likely be better.
ERR_FS_UNKNOWN_FILE_OPEN_FLAG
or something similar
@BridgeAR now that the other PRs landed, could you rework & rebase. Probably could use the new |
904ad1b
to
9949174
Compare
Rebased |
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
9949174
to
16db827
Compare
Rebased. PTAL |
Re: #13937 (comment) @nodejs/ctc |
Can you rebase? This is conflicting with master. |
In addition refactor common.throws to common.expectsError
16db827
to
44d655e
Compare
There is not much left of this after a couple of rebases as there were other PRs that got merged that did the same thing. This is happening very frequently with the internal/errors and I am wondering how it's possible to prevent these duplicates a bit better. I actually stopped opening PRs with ports because of that. I squashed the commits as they individually did not change a lot anymore. |
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
In addition refactor common.throws to common.expectsError PR-URL: nodejs#13829 Refs: nodejs#11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Landed in 095357e |
Ref: #11273
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
internal