-
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: complete error code for validateLen func in internal/fs #19909
Conversation
The prefix for the first commit should just be |
e2469ad
to
0ba1b37
Compare
fixed it, thanks for your suggestion! @mscdex |
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 be nice to also add a test for floating point numbers.
lib/internal/fs.js
Outdated
err = new ERR_INVALID_ARG_TYPE('len', 'number', len); | ||
} else { | ||
} else if (!Number.isInteger(len)) { | ||
// TODO(BridgeAR): Improve this error 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.
You can actually remove my comment now
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.
ok
@@ -350,11 +350,14 @@ function validateLen(len) { | |||
let err; | |||
|
|||
if (!isInt32(len)) { | |||
if (typeof value !== 'number') { | |||
if (typeof len !== '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.
❤️
Fixed the comments. @BridgeAR |
test/parallel/test-fs-truncate.js
Outdated
@@ -190,6 +190,31 @@ function testFtruncate(cb) { | |||
); | |||
}); | |||
|
|||
[-1.5, 1.5].forEach((input) => { | |||
assert.throws( |
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 better to use common.expectsError
in our tests.
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.
Updated. thanks for review :)
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.
@starkwang I must disagree. The original reason for using common.expectsError
is that it allowed to use the error object. Now, assert.throws
is more powerful than common.expectsError
due to a much better error message output and since that feature was added to assert.throws
.
PR-URL: nodejs#19909 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Landed in 61e232b 🎉 I removed the |
PR-URL: #19909 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes