Skip to content

Commit 186857f

Browse files
committed
errors: remove ERR_INVALID_ARRAY_LENGTH
This error code is obsolete, since the error message from ERR_OUT_OF_RANGE is more precise. It was only used a single time, so I went ahead and replced this. PR-URL: #20484 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 28a54cb commit 186857f

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

doc/api/errors.md

-5
Original file line numberDiff line numberDiff line change
@@ -1078,11 +1078,6 @@ An argument of the wrong type was passed to a Node.js API.
10781078

10791079
An invalid or unsupported value was passed for a given argument.
10801080

1081-
<a id="ERR_INVALID_ARRAY_LENGTH"></a>
1082-
### ERR_INVALID_ARRAY_LENGTH
1083-
1084-
An array was not of the expected length or in a valid range.
1085-
10861081
<a id="ERR_INVALID_ASYNC_ID"></a>
10871082
### ERR_INVALID_ASYNC_ID
10881083

lib/internal/errors.js

-4
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,6 @@ E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
865865
}
866866
return `The argument '${name}' ${reason}. Received ${inspected}`;
867867
}, TypeError, RangeError);
868-
E('ERR_INVALID_ARRAY_LENGTH',
869-
(name, len, actual) => {
870-
return `The array "${name}" (length ${actual}) must be of length ${len}.`;
871-
}, TypeError);
872868
E('ERR_INVALID_ASYNC_ID', 'Invalid %s value: %s', RangeError);
873869
E('ERR_INVALID_BUFFER_SIZE',
874870
'Buffer size must be a multiple of %s', RangeError);

lib/internal/process.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const {
66
ERR_ASSERTION,
77
ERR_CPU_USAGE,
88
ERR_INVALID_ARG_TYPE,
9-
ERR_INVALID_ARRAY_LENGTH,
109
ERR_INVALID_OPT_VALUE,
10+
ERR_OUT_OF_RANGE,
1111
ERR_UNCAUGHT_EXCEPTION_CAPTURE_ALREADY_SET,
1212
ERR_UNKNOWN_SIGNAL
1313
}
@@ -108,7 +108,7 @@ function setup_hrtime() {
108108
throw new ERR_INVALID_ARG_TYPE('time', 'Array', time);
109109
}
110110
if (time.length !== 2) {
111-
throw new ERR_INVALID_ARRAY_LENGTH('time', 2, time.length);
111+
throw new ERR_OUT_OF_RANGE('time', 2, time.length);
112112
}
113113

114114
const sec = (hrValues[0] * 0x100000000 + hrValues[1]) - time[0];

test/parallel/test-process-hrtime.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
const common = require('../common');
2424
const assert = require('assert');
2525

26-
// the default behavior, return an Array "tuple" of numbers
26+
// The default behavior, return an Array "tuple" of numbers
2727
const tuple = process.hrtime();
2828

29-
// validate the default behavior
29+
// Validate the default behavior
3030
validateTuple(tuple);
3131

32-
// validate that passing an existing tuple returns another valid tuple
32+
// Validate that passing an existing tuple returns another valid tuple
3333
validateTuple(process.hrtime(tuple));
3434

35-
// test that only an Array may be passed to process.hrtime()
35+
// Test that only an Array may be passed to process.hrtime()
3636
common.expectsError(() => {
3737
process.hrtime(1);
3838
}, {
@@ -43,23 +43,23 @@ common.expectsError(() => {
4343
common.expectsError(() => {
4444
process.hrtime([]);
4545
}, {
46-
code: 'ERR_INVALID_ARRAY_LENGTH',
47-
type: TypeError,
48-
message: 'The array "time" (length 0) must be of length 2.'
46+
code: 'ERR_OUT_OF_RANGE',
47+
type: RangeError,
48+
message: 'The value of "time" is out of range. It must be 2. Received 0'
4949
});
5050
common.expectsError(() => {
5151
process.hrtime([1]);
5252
}, {
53-
code: 'ERR_INVALID_ARRAY_LENGTH',
54-
type: TypeError,
55-
message: 'The array "time" (length 1) must be of length 2.'
53+
code: 'ERR_OUT_OF_RANGE',
54+
type: RangeError,
55+
message: 'The value of "time" is out of range. It must be 2. Received 1'
5656
});
5757
common.expectsError(() => {
5858
process.hrtime([1, 2, 3]);
5959
}, {
60-
code: 'ERR_INVALID_ARRAY_LENGTH',
61-
type: TypeError,
62-
message: 'The array "time" (length 3) must be of length 2.'
60+
code: 'ERR_OUT_OF_RANGE',
61+
type: RangeError,
62+
message: 'The value of "time" is out of range. It must be 2. Received 3'
6363
});
6464

6565
function validateTuple(tuple) {
@@ -70,4 +70,4 @@ function validateTuple(tuple) {
7070
}
7171

7272
const diff = process.hrtime([0, 1e9 - 1]);
73-
assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751
73+
assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751

0 commit comments

Comments
 (0)