lib/fs: convert to using internal/errors#15043
Conversation
lib/fs.js
Outdated
There was a problem hiding this comment.
'object', 'string' [](start = 32, length = 18)
can you have it ['string', 'object'] just to match the earlier error message?
lib/fs.js
Outdated
There was a problem hiding this comment.
Please use ERR_INVALID_CALLBACK here :-)
There was a problem hiding this comment.
And every where that the callback error is emitted :-)
|
looks good in general with a few edits necessary! |
refack
left a comment
There was a problem hiding this comment.
Suggested some improvments
lib/fs.js
Outdated
There was a problem hiding this comment.
IMHO this could be changed to TypeError.
Feedback anyone?
There was a problem hiding this comment.
That's really difficult to say. The coercion to a string means that any value can be used, it's not really a TypeError. The real check here is the null-character bit, which doesn't feel like a TypeError to me. I could live with it tho.
lib/fs.js
Outdated
There was a problem hiding this comment.
- These a disparity with the docs (but out of scope for this PR)
- AFAICT
date stringwill not parse
tl;dr 3rd arg should be ['Date', 'time in seconds']
There was a problem hiding this comment.
2.You are right I will go with ['Date', 'time in seconds']
The date string was (inaccurate) for a string timestamp arg like '1504020561954'
There was a problem hiding this comment.
I updated it to ['Date', 'time in seconds'] (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
I updated it to TypeError (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
IMHO ERR_INVALID_ARG_TYPE might be better.
There was a problem hiding this comment.
I updated it to ERR_INVALID_ARG_TYPE (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
I updated it to ERR_INVALID_ARG_TYPE (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
IMHO ERR_VALUE_OUT_OF_RANGE might be better:
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE',
'start',
'<= "end"',
`{start: ${this.start}, end: ${this.end}}`);to produce:
The value of "start" must be <= "end". Received "{start: 5, end: 4}"
There was a problem hiding this comment.
I updated it to ERR_VALUE_OUT_OF_RANGE and I added the new error ERR_VALUE_OUT_OF_RANGE in errors.js (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
I updated it to ERR_INVALID_ARG_TYPE (commit: 2f0738a)
lib/fs.js
Outdated
There was a problem hiding this comment.
I updated it to ERR_VALUE_OUT_OF_RANGE (commit: 2f0738a)
test/parallel/test-fs-read-stream.js
Outdated
There was a problem hiding this comment.
Just for this case I suggest validating the output message as well
There was a problem hiding this comment.
I added the message assertion (commit: 2f0738a)
|
Hello @pmatzavin and welcome (or is it welcome back?). Thank you for tackling this one, it's a non trivial change 🥇 P.S. If you have any question you can also feel free to contact me directly. |
mhdawson
left a comment
There was a problem hiding this comment.
LGTM thanks for helping with the error conversion.
covert lib/fs.js over to using lib/internal/errors.js i have not addressed the cases that use errnoException(), for reasons described in nodejsGH-12926 - throw the ERR_INVALID_CALLBACK error when the the callback is invalid - replace the ['object', 'string'] with ['string', 'object'] in the error constructor call, to better match the previous err msg in the getOptions() function - add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js, this error is thrown when a numeric value is out of range - document the ERR_VALUE_OUT_OF_RANGE err in errors.md - correct the expected args, in the error thrown in the function fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js) - update the listener error type in the fs.watchFile() function, from Error to TypeError (lib/fs.js) - update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE in the functions fs.ReadStream() and fs.WriteStream(), for the cases of range errors use the new error: ERR_VALUE_OUT_OF_RANGE (lib/fs.js) PR-URL: nodejs#15043 Refs: nodejs#11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2f0738a to
0b1285c
Compare
|
Pre-land sanity: https://ci.nodejs.org/job/node-test-commit-linuxone/8335/ |
covert lib/fs.js over to using lib/internal/errors.js i have not addressed the cases that use errnoException(), for reasons described in nodejsGH-12926 - throw the ERR_INVALID_CALLBACK error when the the callback is invalid - replace the ['object', 'string'] with ['string', 'object'] in the error constructor call, to better match the previous err msg in the getOptions() function - add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js, this error is thrown when a numeric value is out of range - document the ERR_VALUE_OUT_OF_RANGE err in errors.md - correct the expected args, in the error thrown in the function fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js) - update the listener error type in the fs.watchFile() function, from Error to TypeError (lib/fs.js) - update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE in the functions fs.ReadStream() and fs.WriteStream(), for the cases of range errors use the new error: ERR_VALUE_OUT_OF_RANGE (lib/fs.js) PR-URL: nodejs#15043 Refs: nodejs#11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
|
Landed in 219932a |
covert lib/fs.js over to using lib/internal/errors.js i have not addressed the cases that use errnoException(), for reasons described in GH-12926 - throw the ERR_INVALID_CALLBACK error when the the callback is invalid - replace the ['object', 'string'] with ['string', 'object'] in the error constructor call, to better match the previous err msg in the getOptions() function - add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js, this error is thrown when a numeric value is out of range - document the ERR_VALUE_OUT_OF_RANGE err in errors.md - correct the expected args, in the error thrown in the function fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js) - update the listener error type in the fs.watchFile() function, from Error to TypeError (lib/fs.js) - update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE in the functions fs.ReadStream() and fs.WriteStream(), for the cases of range errors use the new error: ERR_VALUE_OUT_OF_RANGE (lib/fs.js) PR-URL: nodejs/node#15043 Refs: nodejs/node#11273 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
covert lib/fs.js over to using lib/internal/errors.js
ref: #11273
i have not addressed the cases that use errnoException(),
for reasons described in GH-12926
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes(https://github.com/nodejs/node/blob/master/CONTRIBUTING.md#commit-message-guidelines)
Affected core subsystem(s)
lib/fs