Skip to content

Commit

Permalink
process: improve hrtime() error message
Browse files Browse the repository at this point in the history
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: nodejs#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>
  • Loading branch information
Trott committed Jul 20, 2017
1 parent 7fdcb68 commit 43e105f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ E('ERR_HTTP_TRAILER_INVALID',
E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
E('ERR_INVALID_ARG_TYPE', invalidArgType);
E('ERR_INVALID_ARRAY_LENGTH',
(name, length, actual) => {
(name, len, actual) => {
assert.strictEqual(typeof actual, 'number');
return `The "${name}" array must have a length of ${
length}. Received length ${actual}`;
return `The array "${name}" (length ${actual}) must be of length ${len}.`;
});
E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s');
E('ERR_INVALID_CALLBACK', 'Callback must be a function');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-process-hrtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ assert.throws(() => {
}, common.expectsError({
code: 'ERR_INVALID_ARRAY_LENGTH',
type: TypeError,
message: 'The "time" array must have a length of 2. Received length 0'
message: 'The array "time" (length 0) must be of length 2.'
}));
assert.throws(() => {
process.hrtime([1]);
}, common.expectsError({
code: 'ERR_INVALID_ARRAY_LENGTH',
type: TypeError,
message: 'The "time" array must have a length of 2. Received length 1'
message: 'The array "time" (length 1) must be of length 2.'
}));
assert.throws(() => {
process.hrtime([1, 2, 3]);
}, common.expectsError({
code: 'ERR_INVALID_ARRAY_LENGTH',
type: TypeError,
message: 'The "time" array must have a length of 2. Received length 3'
message: 'The array "time" (length 3) must be of length 2.'
}));

function validateTuple(tuple) {
Expand Down

0 comments on commit 43e105f

Please sign in to comment.