-
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
lib: add case of no argument to ERR_INVALID_ARG_VALUE in errors.js #21262
Changes from 1 commit
f2f5c0c
e05f49c
7af6bb3
7c1d365
8043755
a8c61fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,8 +291,10 @@ function validateBuffer(buffer) { | |
|
||
function validateOffsetLengthRead(offset, length, bufferLength) { | ||
let err; | ||
|
||
if (offset < 0 || offset >= bufferLength) { | ||
if (bufferLength === 0) { | ||
err = new ERR_INVALID_ARG_VALUE('buffer', 0, | ||
"is empty and can't be written."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, in this code base we use single quotes. Please run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also move this statement in the already existing if statement and change it to an if (offset < 0 || offset >= bufferLength) {
if (bufferLength === 0) {
err = new ERR_OUT_OF_RANGE('bufferLength', '> 0', bufferLength);
} else {
err = new ...;
}
} else ... |
||
} else if (offset < 0 || offset >= bufferLength) { | ||
err = new ERR_OUT_OF_RANGE('offset', `>= 0 && <= ${bufferLength}`, offset); | ||
} else if (length < 0 || offset + length > bufferLength) { | ||
err = new ERR_OUT_OF_RANGE('length', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,15 +41,25 @@ errors.E('TEST_ERROR_2', (a, b) => `${a} ${b}`, Error); | |
assert.strictEqual(err.code, 'TEST_ERROR_2'); | ||
} | ||
|
||
{ | ||
assert.throws( | ||
() => new errors.codes.TEST_ERROR_1(), | ||
{ | ||
message: 'Code: TEST_ERROR_1; The provided arguments ' + | ||
'length (0) does not match the required ones (1).' | ||
} | ||
); | ||
} | ||
// { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we do not leave the code commented in the code base. |
||
// assert.throws(() => new errors.codes.TEST_ERROR_1(){ | ||
// message: 'Code: TEST_ERROR_1; The provided arguments ' + | ||
// 'length (0) does not match the required ones (1).' | ||
// } | ||
// ); | ||
// } | ||
|
||
assert.expectsError(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you write the tests in the corresponding |
||
const fs = require('fs'); | ||
const file = '/home/aditya/node/test/nodetest/testcodes'; | ||
const keyfile = fs.openSync(file, 'r'); | ||
const string = new Uint8Array(); | ||
const num = fs.readSync(keyfile, string, 0, 10, 0); | ||
console.log(num); | ||
}, { code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'Just Testing' | ||
}); | ||
|
||
// Tests for common.expectsError | ||
common.expectsError(() => { | ||
|
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 am not sure I understand this change.