Skip to content

Commit 43e105f

Browse files
committed
process: improve hrtime() error message
Change error message from the form this format: The "time" array must have a length of 2. Received length 0 ...to this format: The array "time" (length 0) must be of length 2. PR-URL: #14324 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent 7fdcb68 commit 43e105f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/internal/errors.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ E('ERR_HTTP_TRAILER_INVALID',
114114
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
115115
E('ERR_INVALID_ARG_TYPE', invalidArgType);
116116
E('ERR_INVALID_ARRAY_LENGTH',
117-
(name, length, actual) => {
117+
(name, len, actual) => {
118118
assert.strictEqual(typeof actual, 'number');
119-
return `The "${name}" array must have a length of ${
120-
length}. Received length ${actual}`;
119+
return `The array "${name}" (length ${actual}) must be of length ${len}.`;
121120
});
122121
E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
123122
E('ERR_INVALID_CALLBACK', 'Callback must be a function');

test/parallel/test-process-hrtime.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ assert.throws(() => {
4545
}, common.expectsError({
4646
code: 'ERR_INVALID_ARRAY_LENGTH',
4747
type: TypeError,
48-
message: 'The "time" array must have a length of 2. Received length 0'
48+
message: 'The array "time" (length 0) must be of length 2.'
4949
}));
5050
assert.throws(() => {
5151
process.hrtime([1]);
5252
}, common.expectsError({
5353
code: 'ERR_INVALID_ARRAY_LENGTH',
5454
type: TypeError,
55-
message: 'The "time" array must have a length of 2. Received length 1'
55+
message: 'The array "time" (length 1) must be of length 2.'
5656
}));
5757
assert.throws(() => {
5858
process.hrtime([1, 2, 3]);
5959
}, common.expectsError({
6060
code: 'ERR_INVALID_ARRAY_LENGTH',
6161
type: TypeError,
62-
message: 'The "time" array must have a length of 2. Received length 3'
62+
message: 'The array "time" (length 3) must be of length 2.'
6363
}));
6464

6565
function validateTuple(tuple) {

0 commit comments

Comments
 (0)