-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
fs: migrate more errors to internal/errors #17667
Conversation
2b87e7d
to
0e284e1
Compare
@@ -782,6 +782,12 @@ Encoding provided to `util.TextDecoder()` API was not one of the | |||
A `Promise` that was callbackified via `util.callbackify()` was rejected with a | |||
falsy value. | |||
|
|||
<a id="ERR_FS_INVALID_SYMLINK_TYPE"></a> |
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 suspect this principle has been decided previously, but maybe not?:
Is it desirable to have such specific codes? Why not just ERR_INVALID_ARG_VALUE
?
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.
it's been debated and I'm good with it either way.
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 be in favor of erring on the side of more general and you can always move to a more specific code later if it turns out it's really needed. But yeah, if there's fierce opinions on both sides, then ¯\(ツ)/¯
if (isUint8Array(buffer)) { | ||
if (position === undefined) | ||
position = null; | ||
if (typeof offset !== 'number') | ||
offset = 0; | ||
if (typeof length !== 'number') | ||
length = buffer.length - offset; | ||
const byteLength = buffer.byteLength; | ||
if (offset > byteLength) | ||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'offset'); |
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.
ERR_OUT_OF_RANGE
is reduced into ERR_VALUE_OUT_OF_RANGE
in #17648. So here would be better to use ERR_VALUE_OUT_OF_RANGE
.
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.
@jasnell ^
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.
yep, was holding off a bit to see if/when #17648 was going to land.
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.
oh.. right, and the latest updates remove the out of range errors anyway so this is no longer relevant ;-)
lib/internal/errors.js
Outdated
@@ -307,6 +307,7 @@ E('ERR_ENCODING_INVALID_ENCODED_DATA', | |||
'The encoded data was not valid for encoding %s'); | |||
E('ERR_ENCODING_NOT_SUPPORTED', 'The "%s" encoding is not supported'); | |||
E('ERR_FALSY_VALUE_REJECTION', 'Promise was rejected with falsy value'); | |||
E('ERR_FS_INVALID_SYMLINK_TYPE', 'Invalid symlink type: %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.
It would justify this new error a bit more if the error message includes a list of valid symlink types
ping @nodejs/tsc |
0e284e1
to
c57266d
Compare
Chose to go with @joyeecheung's suggestion of a more specific error message. PTAL |
0c2cf69
to
a93e157
Compare
Thank you @joyeecheung :-) ... @nodejs/tsc ... need one more TSC sign off please. |
Looks like there was something wrong with linux one, new linux one CI: https://ci.nodejs.org/job/node-test-commit-linuxone/11371/ |
lib/fs.js
Outdated
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', | ||
['string', 'Buffer', 'URL']); | ||
} | ||
if (!Number.isInteger(uid)) |
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 we also check for uid >= 0
? Same question for the other checks in this commit
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 do believe that uid and gid both can be negative in some edge cases.
lib/fs.js
Outdated
@@ -785,20 +785,27 @@ fs.write = function(fd, buffer, offset, length, position, callback) { | |||
callback(err, written || 0, buffer); | |||
} | |||
|
|||
var req = new FSReqWrap(); | |||
if (!Number.isInteger(fd)) | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', '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.
s/number/integer/
lib/fs.js
Outdated
@@ -825,13 +832,22 @@ Object.defineProperty(fs.write, internalUtil.customPromisifyArgs, | |||
// OR | |||
// fs.writeSync(fd, string[, position[, encoding]]); | |||
fs.writeSync = function(fd, buffer, offset, length, position) { | |||
if (!Number.isInteger(fd)) | |||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'fd', '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.
s/number/integer/
if (isUint8Array(buffer)) { | ||
if (position === undefined) | ||
position = null; | ||
if (typeof offset !== 'number') | ||
offset = 0; | ||
if (typeof length !== 'number') | ||
length = buffer.length - offset; | ||
const byteLength = buffer.byteLength; | ||
if (offset > byteLength) | ||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'offset'); |
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
doc/api/errors.md
Outdated
@@ -1604,6 +1610,8 @@ Creation of a [`zlib`][] object failed due to incorrect configuration. | |||
[`dgram.createSocket()`]: dgram.html#dgram_dgram_createsocket_options_callback | |||
[`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE | |||
[`EventEmitter`]: events.html#events_class_eventemitter | |||
[`fs.symlink()`]: fs.html#fs_symlink | |||
[`fs.symlinkSync()`]: fs.html#fs_symlinksymc |
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.
typo: symlinksync
General question about |
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 with the nits already noted addresses
Replacing Another issue with |
Updated to address @bnoordhuis' feedback. @mcollina and @joyeecheung ... please take another look. |
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 with the nit above adressed.
if (isUint8Array(buffer)) { | ||
if (position === undefined) | ||
position = null; | ||
if (typeof offset !== 'number') | ||
offset = 0; | ||
if (typeof length !== 'number') | ||
length = buffer.length - offset; | ||
const byteLength = buffer.byteLength; | ||
if (offset > byteLength) | ||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'offset'); |
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.
@jasnell ^
return TYPE_ERROR("gid must be an unsigned int"); | ||
CHECK_GE(len, 3); | ||
CHECK(args[1]->IsUint32()); | ||
CHECK(args[2]->IsUint32()); |
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.
IsInt32
(both lines)
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.
FChown
is not changed in this PR and also gets Uint32Value()
. Are you sure negative uid and gid are possible?
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... they are definitely theoretically possible but you're right. I'll keep these as uint32s
469c61a
to
4e75058
Compare
4e75058
to
a2d9bd7
Compare
PR-URL: #17667 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Landed in 6100e12 |
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.
Belated LGTM
@jasnell it looks like the new assertions in |
@apapirovski The CITGM issues are caused by |
Next batch of fs type checking migrations to use internal/errors
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs