diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/child_process.js | 4 | ||||
-rw-r--r-- | lib/events.js | 8 | ||||
-rw-r--r-- | lib/fs.js | 4 | ||||
-rw-r--r-- | lib/internal/crypto/pbkdf2.js | 5 | ||||
-rw-r--r-- | lib/internal/errors.js | 12 | ||||
-rw-r--r-- | lib/internal/http2/core.js | 3 | ||||
-rw-r--r-- | lib/internal/timers.js | 2 |
7 files changed, 25 insertions, 13 deletions
diff --git a/lib/child_process.js b/lib/child_process.js index c4512ab2f4..d1c4d2f290 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -650,7 +650,7 @@ exports.execSync = execSync; function validateTimeout(timeout) { if (timeout != null && !(Number.isInteger(timeout) && timeout >= 0)) { - throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'timeout', 'an unsigned integer', timeout); @@ -660,7 +660,7 @@ function validateTimeout(timeout) { function validateMaxBuffer(maxBuffer) { if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) { - throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'options.maxBuffer', 'a positive number', maxBuffer); diff --git a/lib/events.js b/lib/events.js index 28a8c4228b..9ad5ec376f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -56,7 +56,10 @@ Object.defineProperty(EventEmitter, 'defaultMaxListeners', { // greater and not a NaN). if (typeof arg !== 'number' || arg < 0 || arg !== arg) { const errors = lazyErrors(); - throw new errors.TypeError('ERR_OUT_OF_RANGE', 'defaultMaxListeners'); + throw new errors.RangeError('ERR_OUT_OF_RANGE', + 'defaultMaxListeners', + 'a non-negative number', + arg); } defaultMaxListeners = arg; } @@ -78,7 +81,8 @@ EventEmitter.init = function() { EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { if (typeof n !== 'number' || n < 0 || isNaN(n)) { const errors = lazyErrors(); - throw new errors.TypeError('ERR_OUT_OF_RANGE', 'n'); + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'n', + 'a non-negative number', n); } this._maxListeners = n; return this; @@ -2353,7 +2353,7 @@ function ReadStream(path, options) { if (this.start > this.end) { const errVal = `{start: ${this.start}, end: ${this.end}}`; - throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'start', '<= "end"', errVal); @@ -2511,7 +2511,7 @@ function WriteStream(path, options) { } if (this.start < 0) { const errVal = `{start: ${this.start}}`; - throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'start', '>= 0', errVal); diff --git a/lib/internal/crypto/pbkdf2.js b/lib/internal/crypto/pbkdf2.js index 2fc211a87d..e967e0a794 100644 --- a/lib/internal/crypto/pbkdf2.js +++ b/lib/internal/crypto/pbkdf2.js @@ -52,7 +52,10 @@ function _pbkdf2(password, salt, iterations, keylen, digest, callback) { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'iterations', 'number'); if (iterations < 0) - throw new errors.RangeError('ERR_OUT_OF_RANGE', 'iterations'); + throw new errors.RangeError('ERR_OUT_OF_RANGE', + 'iterations', + 'a non-negative number', + iterations); if (typeof keylen !== 'number') throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'keylen', 'number'); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index c15c85b554..9e3d1a9355 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -444,7 +444,7 @@ E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support'); E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU'); E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported'); E('ERR_OUTOFMEMORY', 'Out of memory'); -E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range'); +E('ERR_OUT_OF_RANGE', outOfRange); E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s'); E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s'); E('ERR_SCRIPT_EXECUTION_INTERRUPTED', @@ -505,9 +505,6 @@ E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.com/nodejs/node/wiki/Intl'); E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', 'At least one valid performance entry type is required'); -E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => { - return `The value of "${start}" must be ${end}. Received "${value}"`; -}); E('ERR_ZLIB_BINDING_CLOSED', 'zlib binding closed'); E('ERR_ZLIB_INITIALIZATION_FAILED', 'Initialization failed'); @@ -620,3 +617,10 @@ function invalidChar(name, field) { } return msg; } + +function outOfRange(name, range, value) { + let msg = `The value of "${name}" is out of range.`; + if (range) msg += ` It must be ${range}.`; + if (value !== undefined) msg += ` Received ${value}`; + return msg; +} diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 141f7fd016..e2ce4071d7 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -851,7 +851,8 @@ class Http2Session extends EventEmitter { if (typeof id !== 'number') throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'id', 'number'); if (id <= 0 || id > kMaxStreams) - throw new errors.RangeError('ERR_OUT_OF_RANGE'); + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'id', + `> 0 and <= ${kMaxStreams}`, id); this[kHandle].setNextStreamID(id); } diff --git a/lib/internal/timers.js b/lib/internal/timers.js index e4fbc6e0a3..e541622021 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -115,7 +115,7 @@ function validateTimerDuration(msecs) { } if (msecs < 0 || !isFinite(msecs)) { - throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', 'msecs', + throw new errors.RangeError('ERR_OUT_OF_RANGE', 'msecs', 'a non-negative finite number', msecs); } |