| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -558,6 +558,14 @@ found [here][online]. | |||
| 558 | 558 | the connected party did not properly respond after a period of time. Usually | |
| 559 | 559 | encountered by [`http`][] or [`net`][] -- often a sign that a `socket.end()` | |
| 560 | 560 | was not properly called. | |
| 561 | + | ||
| 562 | + <a id="ERROR_CODES"></a> | ||
| 563 | + ### ERROR CODES | ||
| 564 | + | ||
| 565 | + <a id="ERR_INDEX_OUT_OF_RANGE"></a> | ||
| 566 | + ### ERR_INDEX_OUT_OF_RANGE | ||
| 567 | + | ||
| 568 | + The `'ERR_INDEX_OUT_OF_RANGE'` error code is used when a given index is out of the accepted range. | ||
| 561 | 569 | ||
| 562 | 570 | ||
| 563 | 571 | <a id="nodejs-error-codes"></a> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,6 +28,7 @@ const { isAnyArrayBuffer, isUint8Array } = process.binding('util'); | |||
| 28 | 28 | const bindingObj = {}; | |
| 29 | 29 | const internalUtil = require('internal/util'); | |
| 30 | 30 | const pendingDeprecation = !!config.pendingDeprecation; | |
| 31 | + const errors = require('internal/errors'); | ||
| 31 | 32 | ||
| 32 | 33 | class FastBuffer extends Uint8Array { | |
| 33 | 34 | constructor(arg1, arg2, arg3) { | |
@@ -629,28 +630,28 @@ Buffer.prototype.compare = function compare(target, | |||
| 629 | 630 | if (start === undefined) | |
| 630 | 631 | start = 0; | |
| 631 | 632 | else if (start < 0) | |
| 632 | - throw new RangeError('out of range index'); | ||
| 633 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 633 | 634 | else | |
| 634 | 635 | start >>>= 0; | |
| 635 | 636 | ||
| 636 | 637 | if (end === undefined) | |
| 637 | 638 | end = target.length; | |
| 638 | 639 | else if (end > target.length) | |
| 639 | - throw new RangeError('out of range index'); | ||
| 640 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 640 | 641 | else | |
| 641 | 642 | end >>>= 0; | |
| 642 | 643 | ||
| 643 | 644 | if (thisStart === undefined) | |
| 644 | 645 | thisStart = 0; | |
| 645 | 646 | else if (thisStart < 0) | |
| 646 | - throw new RangeError('out of range index'); | ||
| 647 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 647 | 648 | else | |
| 648 | 649 | thisStart >>>= 0; | |
| 649 | 650 | ||
| 650 | 651 | if (thisEnd === undefined) | |
| 651 | 652 | thisEnd = this.length; | |
| 652 | 653 | else if (thisEnd > this.length) | |
| 653 | - throw new RangeError('out of range index'); | ||
| 654 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 654 | 655 | else | |
| 655 | 656 | thisEnd >>>= 0; | |
| 656 | 657 | ||
@@ -795,7 +796,7 @@ Buffer.prototype.fill = function fill(val, start, end, encoding) { | |||
| 795 | 796 | ||
| 796 | 797 | // Invalid ranges are not set to a default, so can range check early. | |
| 797 | 798 | if (start < 0 || end > this.length) | |
| 798 | - throw new RangeError('Out of range index'); | ||
| 799 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 799 | 800 | ||
| 800 | 801 | if (end <= start) | |
| 801 | 802 | return this; | |
@@ -931,7 +932,7 @@ Buffer.prototype.slice = function slice(start, end) { | |||
| 931 | 932 | ||
| 932 | 933 | function checkOffset(offset, ext, length) { | |
| 933 | 934 | if (offset + ext > length) | |
| 934 | - throw new RangeError('Index out of range'); | ||
| 935 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 935 | 936 | } | |
| 936 | 937 | ||
| 937 | 938 | ||
@@ -1141,7 +1142,7 @@ function checkInt(buffer, value, offset, ext, max, min) { | |||
| 1141 | 1142 | if (value > max || value < min) | |
| 1142 | 1143 | throw new TypeError('"value" argument is out of bounds'); | |
| 1143 | 1144 | if (offset + ext > buffer.length) | |
| 1144 | - throw new RangeError('Index out of range'); | ||
| 1145 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 1145 | 1146 | } | |
| 1146 | 1147 | ||
| 1147 | 1148 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,6 +114,7 @@ E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); | |||
| 114 | 114 | E('ERR_ASSERTION', (msg) => msg); | |
| 115 | 115 | E('ERR_CONSOLE_WRITABLE_STREAM', | |
| 116 | 116 | (name) => `Console expects a writable stream instance for ${name}`); | |
| 117 | + E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | ||
| 117 | 118 | E('ERR_INVALID_ARG_TYPE', invalidArgType); | |
| 118 | 119 | E('ERR_INVALID_CALLBACK', 'callback must be a function'); | |
| 119 | 120 | E('ERR_INVALID_FILE_URL_HOST', 'File URL host %s'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ | |||
| 40 | 40 | ||
| 41 | 41 | #define THROW_AND_RETURN_IF_OOB(r) \ | |
| 42 | 42 | do { \ | |
| 43 | - if (!(r)) return env->ThrowRangeError("out of range index"); \ | ||
| 43 | + if (!(r)) return env->ThrowRangeError("Index out of range"); \ | ||
| 44 | 44 | } while (0) | |
| 45 | 45 | ||
| 46 | 46 | #define SLICE_START_END(start_arg, end_arg, end_max) \ | |
@@ -564,7 +564,7 @@ void Copy(const FunctionCallbackInfo<Value> &args) { | |||
| 564 | 564 | return args.GetReturnValue().Set(0); | |
| 565 | 565 | ||
| 566 | 566 | if (source_start > ts_obj_length) | |
| 567 | - return env->ThrowRangeError("out of range index"); | ||
| 567 | + return env->ThrowRangeError("Index out of range"); | ||
| 568 | 568 | ||
| 569 | 569 | if (source_end - source_start > target_length - target_start) | |
| 570 | 570 | source_end = source_start + target_length - target_start; | |
@@ -878,9 +878,9 @@ void CompareOffset(const FunctionCallbackInfo<Value> &args) { | |||
| 878 | 878 | THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[5], ts_obj_length, &source_end)); | |
| 879 | 879 | ||
| 880 | 880 | if (source_start > ts_obj_length) | |
| 881 | - return env->ThrowRangeError("out of range index"); | ||
| 881 | + return env->ThrowRangeError("Index out of range"); | ||
| 882 | 882 | if (target_start > target_length) | |
| 883 | - return env->ThrowRangeError("out of range index"); | ||
| 883 | + return env->ThrowRangeError("Index out of range"); | ||
| 884 | 884 | ||
| 885 | 885 | CHECK_LE(source_start, source_end); | |
| 886 | 886 | CHECK_LE(target_start, target_end); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -963,7 +963,8 @@ assert.throws(() => { | |||
| 963 | 963 | const a = Buffer.alloc(1); | |
| 964 | 964 | const b = Buffer.alloc(1); | |
| 965 | 965 | a.copy(b, 0, 0x100000000, 0x100000001); | |
| 966 | - }, /out of range index/); | ||
| 966 | + }, common.expectsError( | ||
| 967 | + {code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 967 | 968 | ||
| 968 | 969 | // Unpooled buffer (replaces SlowBuffer) | |
| 969 | 970 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | ||
| 6 | 6 | const a = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); | |
@@ -57,7 +57,7 @@ assert.strictEqual(1, a.compare(b, Infinity, -Infinity)); | |||
| 57 | 57 | // zero length target because default for targetEnd <= targetSource | |
| 58 | 58 | assert.strictEqual(1, a.compare(b, '0xff')); | |
| 59 | 59 | ||
| 60 | - const oor = /out of range index/; | ||
| 60 | + const oor = common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'}); | ||
| 61 | 61 | ||
| 62 | 62 | assert.throws(() => a.compare(b, 0, 100, 0), oor); | |
| 63 | 63 | assert.throws(() => a.compare(b, 0, 1, 0, 100), oor); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | - | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | const assert = require('assert'); | |
| 5 | + const errors = require('internal/errors'); | ||
| 5 | 6 | const SIZE = 28; | |
| 6 | 7 | ||
| 7 | 8 | const buf1 = Buffer.allocUnsafe(SIZE); | |
@@ -191,25 +192,30 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, -1]), [0, 0, 0, 0]); | |||
| 191 | 192 | ||
| 192 | 193 | ||
| 193 | 194 | // Check exceptions | |
| 194 | - assert.throws(() => buf1.fill(0, -1), /^RangeError: Out of range index$/); | ||
| 195 | - assert.throws(() => | ||
| 196 | - buf1.fill(0, 0, buf1.length + 1), | ||
| 197 | - /^RangeError: Out of range index$/); | ||
| 198 | - assert.throws(() => buf1.fill('', -1), /^RangeError: Out of range index$/); | ||
| 199 | - assert.throws(() => | ||
| 200 | - buf1.fill('', 0, buf1.length + 1), | ||
| 201 | - /^RangeError: Out of range index$/); | ||
| 202 | - assert.throws(() => | ||
| 203 | - buf1.fill('a', 0, buf1.length, 'node rocks!'), | ||
| 204 | - /^TypeError: Unknown encoding: node rocks!$/); | ||
| 205 | - assert.throws(() => | ||
| 206 | - buf1.fill('a', 0, 0, NaN), | ||
| 207 | - /^TypeError: encoding must be a string$/); | ||
| 208 | - assert.throws(() => | ||
| 209 | - buf1.fill('a', 0, 0, null), | ||
| 210 | - /^TypeError: encoding must be a string$/); | ||
| 211 | - assert.throws(() => | ||
| 212 | - buf1.fill('a', 0, 0, 'foo'), /^TypeError: Unknown encoding: foo$/); | ||
| 195 | + assert.throws( | ||
| 196 | + () => buf1.fill(0, -1), | ||
| 197 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 198 | + assert.throws( | ||
| 199 | + () => buf1.fill(0, 0, buf1.length + 1), | ||
| 200 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 201 | + assert.throws( | ||
| 202 | + () => buf1.fill('', -1), | ||
| 203 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 204 | + assert.throws( | ||
| 205 | + () => buf1.fill('', 0, buf1.length + 1), | ||
| 206 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 207 | + assert.throws( | ||
| 208 | + () => buf1.fill('a', 0, buf1.length, 'node rocks!'), | ||
| 209 | + /^TypeError: Unknown encoding: node rocks!$/); | ||
| 210 | + assert.throws( | ||
| 211 | + () => buf1.fill('a', 0, 0, NaN), | ||
| 212 | + /^TypeError: encoding must be a string$/); | ||
| 213 | + assert.throws( | ||
| 214 | + () => buf1.fill('a', 0, 0, null), | ||
| 215 | + /^TypeError: encoding must be a string$/); | ||
| 216 | + assert.throws( | ||
| 217 | + () => buf1.fill('a', 0, 0, 'foo'), | ||
| 218 | + /^TypeError: Unknown encoding: foo$/); | ||
| 213 | 219 | ||
| 214 | 220 | ||
| 215 | 221 | function genBuffer(size, args) { | |
@@ -241,7 +247,7 @@ function writeToFill(string, offset, end, encoding) { | |||
| 241 | 247 | } | |
| 242 | 248 | ||
| 243 | 249 | if (offset < 0 || end > buf2.length) | |
| 244 | - throw new RangeError('Out of range index'); | ||
| 250 | + throw new errors.RangeError('ERR_INDEX_OUT_OF_RANGE'); | ||
| 245 | 251 | ||
| 246 | 252 | if (end <= offset) | |
| 247 | 253 | return buf2; | |
@@ -279,12 +285,12 @@ function testBufs(string, offset, length, encoding) { | |||
| 279 | 285 | } | |
| 280 | 286 | ||
| 281 | 287 | // Make sure these throw. | |
| 282 | - assert.throws(() => | ||
| 283 | - Buffer.allocUnsafe(8).fill('a', -1), | ||
| 284 | - /^RangeError: Out of range index$/); | ||
| 285 | - assert.throws(() => | ||
| 286 | - Buffer.allocUnsafe(8).fill('a', 0, 9), | ||
| 287 | - /^RangeError: Out of range index$/); | ||
| 288 | + assert.throws( | ||
| 289 | + () => Buffer.allocUnsafe(8).fill('a', -1), | ||
| 290 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 291 | + assert.throws( | ||
| 292 | + () => Buffer.allocUnsafe(8).fill('a', 0, 9), | ||
| 293 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'})); | ||
| 288 | 294 | ||
| 289 | 295 | // Make sure this doesn't hang indefinitely. | |
| 290 | 296 | Buffer.allocUnsafe(8).fill(''); | |
@@ -350,7 +356,8 @@ Buffer.alloc(8, ''); | |||
| 350 | 356 | } | |
| 351 | 357 | }; | |
| 352 | 358 | Buffer.alloc(1).fill(Buffer.alloc(1), start, 1); | |
| 353 | - }, /out of range index/); | ||
| 359 | + }, common.expectsError( | ||
| 360 | + {code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 354 | 361 | // Make sure -1 is making it to Buffer::Fill(). | |
| 355 | 362 | assert.ok(elseWasLast, | |
| 356 | 363 | 'internal API changed, -1 no longer in correct location'); | |
@@ -360,7 +367,8 @@ Buffer.alloc(8, ''); | |||
| 360 | 367 | // around. | |
| 361 | 368 | assert.throws(() => { | |
| 362 | 369 | process.binding('buffer').fill(Buffer.alloc(1), 1, -1, 0, 1); | |
| 363 | - }, /out of range index/); | ||
| 370 | + }, common.expectsError( | ||
| 371 | + {code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 364 | 372 | ||
| 365 | 373 | // Make sure "end" is properly checked, even if it's magically mangled using | |
| 366 | 374 | // Symbol.toPrimitive. | |
@@ -383,7 +391,8 @@ assert.throws(() => { | |||
| 383 | 391 | } | |
| 384 | 392 | }; | |
| 385 | 393 | Buffer.alloc(1).fill(Buffer.alloc(1), 0, end); | |
| 386 | - }, /^RangeError: out of range index$/); | ||
| 394 | + }, common.expectsError( | ||
| 395 | + {code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 387 | 396 | // Make sure -1 is making it to Buffer::Fill(). | |
| 388 | 397 | assert.ok(elseWasLast, | |
| 389 | 398 | 'internal API changed, -1 no longer in correct location'); | |
@@ -393,7 +402,8 @@ assert.throws(() => { | |||
| 393 | 402 | // around. | |
| 394 | 403 | assert.throws(() => { | |
| 395 | 404 | process.binding('buffer').fill(Buffer.alloc(1), 1, 1, -2, 1); | |
| 396 | - }, /out of range index/); | ||
| 405 | + }, common.expectsError( | ||
| 406 | + { code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 397 | 407 | ||
| 398 | 408 | // Test that bypassing 'length' won't cause an abort. | |
| 399 | 409 | assert.throws(() => { | |
@@ -403,7 +413,8 @@ assert.throws(() => { | |||
| 403 | 413 | enumerable: true | |
| 404 | 414 | }); | |
| 405 | 415 | buf.fill(''); | |
| 406 | - }, /^RangeError: out of range index$/); | ||
| 416 | + }, common.expectsError( | ||
| 417 | + { code: undefined, type: RangeError, message: 'Index out of range'})); | ||
| 407 | 418 | ||
| 408 | 419 | assert.deepStrictEqual( | |
| 409 | 420 | Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | ||
| 5 | 5 | // testing basic buffer read functions | |
@@ -10,7 +10,7 @@ function read(buff, funx, args, expected) { | |||
| 10 | 10 | assert.strictEqual(buff[funx](...args), expected); | |
| 11 | 11 | assert.throws( | |
| 12 | 12 | () => buff[funx](-1), | |
| 13 | - /^RangeError: Index out of range$/ | ||
| 13 | + common.expectsError({code: 'ERR_INDEX_OUT_OF_RANGE'}) | ||
| 14 | 14 | ); | |
| 15 | 15 | ||
| 16 | 16 | assert.doesNotThrow( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ const assert = require('assert'); | |||
| 4 | 4 | ||
| 5 | 5 | // testing buffer write functions | |
| 6 | 6 | ||
| 7 | - const outOfRange = /^RangeError: (?:Index )?out of range(?: index)?$/; | ||
| 7 | + const outOfRange = /^RangeError\b.*\bIndex out of range$/; | ||
| 8 | 8 | ||
| 9 | 9 | function write(funx, args, result, res) { | |
| 10 | 10 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments