Skip to content

Commit d022cb1

Browse files
committedDec 24, 2017
lib: combine similar error codes
There two similar error codes in lib: "ERR_VALUE_OUT_OF_RANGE" and "ERR_OUT_OF_RANGE". This change is to reduce them into "ERR_VALUE_OUT_OF_RANGE" Fixes: #17603 PR-URL: #17648 Fixes: #17603 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 4d74b52 commit d022cb1

17 files changed

+70
-42
lines changed
 

‎doc/api/errors.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ An operation caused an out-of-memory condition.
13401340
<a id="ERR_OUT_OF_RANGE"></a>
13411341
### ERR_OUT_OF_RANGE
13421342

1343-
An input argument value was outside an acceptable range.
1343+
A given value is out of the accepted range.
13441344

13451345
<a id="ERR_PARSE_HISTORY_DATA"></a>
13461346
### ERR_PARSE_HISTORY_DATA
@@ -1609,7 +1609,7 @@ entry types were found.
16091609
<a id="ERR_VALUE_OUT_OF_RANGE"></a>
16101610
### ERR_VALUE_OUT_OF_RANGE
16111611

1612-
A given value is out of the accepted range.
1612+
Superseded by `ERR_OUT_OF_RANGE`
16131613

16141614
<a id="ERR_ZLIB_BINDING_CLOSED"></a>
16151615
### ERR_ZLIB_BINDING_CLOSED

‎lib/child_process.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ exports.execSync = execSync;
650650

651651
function validateTimeout(timeout) {
652652
if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) {
653-
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE',
653+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
654654
'timeout',
655655
'an unsigned integer',
656656
timeout);
@@ -660,7 +660,7 @@ function validateTimeout(timeout) {
660660

661661
function validateMaxBuffer(maxBuffer) {
662662
if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) {
663-
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE',
663+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
664664
'options.maxBuffer',
665665
'a positive number',
666666
maxBuffer);

‎lib/events.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
5656
// greater and not a NaN).
5757
if (typeof arg !== 'number' || arg < 0 || arg !== arg) {
5858
const errors = lazyErrors();
59-
throw new errors.TypeError('ERR_OUT_OF_RANGE', 'defaultMaxListeners');
59+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
60+
'defaultMaxListeners',
61+
'a non-negative number',
62+
arg);
6063
}
6164
defaultMaxListeners = arg;
6265
}
@@ -78,7 +81,8 @@ EventEmitter.init = function() {
7881
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
7982
if (typeof n !== 'number' || n < 0 || isNaN(n)) {
8083
const errors = lazyErrors();
81-
throw new errors.TypeError('ERR_OUT_OF_RANGE', 'n');
84+
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'n',
85+
'a non-negative number', n);
8286
}
8387
this._maxListeners = n;
8488
return this;

‎lib/fs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ function ReadStream(path, options) {
23532353

23542354
if (this.start > this.end) {
23552355
const errVal = `{start: ${this.start}, end: ${this.end}}`;
2356-
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE',
2356+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
23572357
'start',
23582358
'<= "end"',
23592359
errVal);
@@ -2511,7 +2511,7 @@ function WriteStream(path, options) {
25112511
}
25122512
if (this.start < 0) {
25132513
const errVal = `{start: ${this.start}}`;
2514-
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE',
2514+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
25152515
'start',
25162516
'>= 0',
25172517
errVal);

‎lib/internal/crypto/pbkdf2.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ function _pbkdf2(password, salt, iterations, keylen, digest, callback) {
5252
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'iterations', 'number');
5353

5454
if (iterations < 0)
55-
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'iterations');
55+
throw new errors.RangeError('ERR_OUT_OF_RANGE',
56+
'iterations',
57+
'a non-negative number',
58+
iterations);
5659

5760
if (typeof keylen !== 'number')
5861
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'keylen', 'number');

‎lib/internal/errors.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
444444
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
445445
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
446446
E('ERR_OUTOFMEMORY', 'Out of memory');
447-
E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range');
447+
E('ERR_OUT_OF_RANGE', outOfRange);
448448
E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
449449
E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s');
450450
E('ERR_SCRIPT_EXECUTION_INTERRUPTED',
@@ -505,9 +505,6 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
505505
'See https://github.com/nodejs/node/wiki/Intl');
506506
E('ERR_VALID_PERFORMANCE_ENTRY_TYPE',
507507
'At least one valid performance entry type is required');
508-
E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => {
509-
return `The value of "${start}" must be ${end}. Received "${value}"`;
510-
});
511508
E('ERR_ZLIB_BINDING_CLOSED', 'zlib binding closed');
512509
E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed');
513510

@@ -620,3 +617,10 @@ function invalidChar(name, field) {
620617
}
621618
return msg;
622619
}
620+
621+
function outOfRange(name, range, value) {
622+
let msg = `The value of "${name}" is out of range.`;
623+
if (range) msg += ` It must be ${range}.`;
624+
if (value !== undefined) msg += ` Received ${value}`;
625+
return msg;
626+
}

‎lib/internal/http2/core.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ class Http2Session extends EventEmitter {
851851
if (typeof id !== 'number')
852852
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'id', 'number');
853853
if (id <= 0 || id > kMaxStreams)
854-
throw new errors.RangeError('ERR_OUT_OF_RANGE');
854+
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'id',
855+
`> 0 and <= ${kMaxStreams}`, id);
855856
this[kHandle].setNextStreamID(id);
856857
}
857858

‎lib/internal/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function validateTimerDuration(msecs) {
115115
}
116116

117117
if (msecs < 0 || !isFinite(msecs)) {
118-
throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', 'msecs',
118+
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'msecs',
119119
'a non-negative finite number', msecs);
120120
}
121121

‎test/parallel/test-child-process-spawnsync-validation-errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (common.isWindows) {
1515
}
1616

1717
const invalidRangeError =
18-
common.expectsError({ code: 'ERR_VALUE_OUT_OF_RANGE', type: RangeError }, 20);
18+
common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);
1919

2020
function pass(option, value) {
2121
// Run the command with the specified option. Since it's not a real command,

‎test/parallel/test-crypto-pbkdf2.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ common.expectsError(
7070
{
7171
code: 'ERR_OUT_OF_RANGE',
7272
type: RangeError,
73-
message: 'The "iterations" argument is out of range'
73+
message: 'The value of "iterations" is out of range. ' +
74+
'It must be a non-negative number. Received -1'
7475
}
7576
);
7677

@@ -93,7 +94,7 @@ common.expectsError(
9394
}, {
9495
code: 'ERR_OUT_OF_RANGE',
9596
type: RangeError,
96-
message: 'The "keylen" argument is out of range'
97+
message: 'The value of "keylen" is out of range.'
9798
});
9899
});
99100

‎test/parallel/test-crypto-random.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ process.setMaxListeners(256);
291291
{
292292
code: 'ERR_OUT_OF_RANGE',
293293
type: RangeError,
294-
message: 'The "offset" argument is out of range'
294+
message: 'The value of "offset" is out of range.'
295295
}
296296
);
297297

@@ -300,7 +300,7 @@ process.setMaxListeners(256);
300300
{
301301
code: 'ERR_OUT_OF_RANGE',
302302
type: RangeError,
303-
message: 'The "offset" argument is out of range'
303+
message: 'The value of "offset" is out of range.'
304304
}
305305
);
306306

@@ -309,7 +309,7 @@ process.setMaxListeners(256);
309309
{
310310
code: 'ERR_OUT_OF_RANGE',
311311
type: RangeError,
312-
message: 'The "offset" argument is out of range'
312+
message: 'The value of "offset" is out of range.'
313313
}
314314
);
315315

@@ -318,7 +318,7 @@ process.setMaxListeners(256);
318318
{
319319
code: 'ERR_OUT_OF_RANGE',
320320
type: RangeError,
321-
message: 'The "offset" argument is out of range'
321+
message: 'The value of "offset" is out of range.'
322322
}
323323
);
324324

@@ -421,7 +421,7 @@ process.setMaxListeners(256);
421421
{
422422
code: 'ERR_OUT_OF_RANGE',
423423
type: RangeError,
424-
message: 'The "size" argument is out of range'
424+
message: 'The value of "size" is out of range.'
425425
}
426426
);
427427

@@ -430,7 +430,7 @@ process.setMaxListeners(256);
430430
{
431431
code: 'ERR_OUT_OF_RANGE',
432432
type: RangeError,
433-
message: 'The "size" argument is out of range'
433+
message: 'The value of "size" is out of range.'
434434
}
435435
);
436436

@@ -439,7 +439,7 @@ process.setMaxListeners(256);
439439
{
440440
code: 'ERR_OUT_OF_RANGE',
441441
type: RangeError,
442-
message: 'The "size" argument is out of range'
442+
message: 'The value of "size" is out of range.'
443443
}
444444
);
445445

@@ -448,7 +448,7 @@ process.setMaxListeners(256);
448448
{
449449
code: 'ERR_OUT_OF_RANGE',
450450
type: RangeError,
451-
message: 'The "size" argument is out of range'
451+
message: 'The value of "size" is out of range.'
452452
}
453453
);
454454

‎test/parallel/test-event-emitter-max-listeners.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ for (const obj of throwsObjs) {
3636
() => e.setMaxListeners(obj),
3737
{
3838
code: 'ERR_OUT_OF_RANGE',
39-
type: TypeError,
40-
message: 'The "n" argument is out of range'
39+
type: RangeError,
40+
message: 'The value of "n" is out of range. ' +
41+
`It must be a non-negative number. Received ${obj}`
4142
}
4243
);
4344

4445
common.expectsError(
4546
() => events.defaultMaxListeners = obj,
4647
{
4748
code: 'ERR_OUT_OF_RANGE',
48-
type: TypeError,
49-
message: 'The "defaultMaxListeners" argument is out of range'
49+
type: RangeError,
50+
message: 'The value of "defaultMaxListeners" is out of range. ' +
51+
`It must be a non-negative number. Received ${obj}`
5052
}
5153
);
5254
}

‎test/parallel/test-file-write-stream3.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ const run_test_4 = common.mustCall(function() {
180180
fs.createWriteStream(filepath, { start: -5, flags: 'r+' });
181181
};
182182
const err = {
183-
code: 'ERR_VALUE_OUT_OF_RANGE',
184-
message: 'The value of "start" must be >= 0. Received "{start: -5}"',
183+
code: 'ERR_OUT_OF_RANGE',
184+
message: 'The value of "start" is out of range. ' +
185+
'It must be >= 0. Received {start: -5}',
185186
type: RangeError
186187
};
187188
common.expectsError(block, err);

‎test/parallel/test-fs-read-stream-inherit.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ const rangeFile = fixtures.path('x.txt');
110110

111111
{
112112
const message =
113-
'The value of "start" must be <= "end". Received "{start: 10, end: 2}"';
113+
'The value of "start" is out of range. It must be <= "end". ' +
114+
'Received {start: 10, end: 2}';
114115

115116
common.expectsError(
116117
() => {
117118
fs.createReadStream(rangeFile, Object.create({ start: 10, end: 2 }));
118119
},
119120
{
120-
code: 'ERR_VALUE_OUT_OF_RANGE',
121+
code: 'ERR_OUT_OF_RANGE',
121122
message,
122123
type: RangeError
123124
});

‎test/parallel/test-fs-read-stream.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ common.expectsError(
145145
fs.createReadStream(rangeFile, { start: 10, end: 2 });
146146
},
147147
{
148-
code: 'ERR_VALUE_OUT_OF_RANGE',
149-
message:
150-
'The value of "start" must be <= "end". Received "{start: 10, end: 2}"',
148+
code: 'ERR_OUT_OF_RANGE',
149+
message: 'The value of "start" is out of range. It must be <= "end". ' +
150+
'Received {start: 10, end: 2}',
151151
type: RangeError
152152
});
153153

‎test/parallel/test-internal-errors.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,18 @@ assert.strictEqual(
281281
);
282282

283283
assert.strictEqual(
284-
errors.message('ERR_VALUE_OUT_OF_RANGE', ['A', 'some values', 'B']),
285-
'The value of "A" must be some values. Received "B"'
284+
errors.message('ERR_OUT_OF_RANGE', ['A']),
285+
'The value of "A" is out of range.'
286+
);
287+
288+
assert.strictEqual(
289+
errors.message('ERR_OUT_OF_RANGE', ['A', 'some values']),
290+
'The value of "A" is out of range. It must be some values.'
291+
);
292+
293+
assert.strictEqual(
294+
errors.message('ERR_OUT_OF_RANGE', ['A', 'some values', 'B']),
295+
'The value of "A" is out of range. It must be some values. Received B'
286296
);
287297

288298
assert.strictEqual(

‎test/parallel/test-timers-enroll-invalid-msecs.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ const timers = require('timers');
2727
common.expectsError(
2828
() => timers.enroll({}, val),
2929
{
30-
code: 'ERR_VALUE_OUT_OF_RANGE',
30+
code: 'ERR_OUT_OF_RANGE',
3131
type: RangeError,
32-
message: 'The value of "msecs" must be a non-negative ' +
33-
`finite number. Received "${val}"`
32+
message: 'The value of "msecs" is out of range. ' +
33+
'It must be a non-negative finite number. ' +
34+
`Received ${val}`
3435
}
3536
);
3637
});

0 commit comments

Comments
 (0)
Please sign in to comment.