From 43e105f6453d50bb667a028d8e85d1882818d16a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 17 Jul 2017 05:15:11 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/14324 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Gibson Fahnestock --- lib/internal/errors.js | 5 ++--- test/parallel/test-process-hrtime.js | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 9fb0ac07dc053b..4cc7bfad86dac9 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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'); diff --git a/test/parallel/test-process-hrtime.js b/test/parallel/test-process-hrtime.js index faf05fef112cb7..5ca9be72d14d63 100644 --- a/test/parallel/test-process-hrtime.js +++ b/test/parallel/test-process-hrtime.js @@ -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) {