diff options
author | Rich Trott <rtrott@gmail.com> | 2018-09-19 20:04:47 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-09-26 19:36:50 -0700 |
commit | f8d69911bef0ddd150d0f66f7a75b4655cf60b00 (patch) | |
tree | 7440234fc5d932a09f276db9f5f2c700fae7591c /test | |
parent | 884dbe9b7f21414b628da43c7016de742ef39454 (diff) | |
download | android-node-v8-f8d69911bef0ddd150d0f66f7a75b4655cf60b00.tar.gz android-node-v8-f8d69911bef0ddd150d0f66f7a75b4655cf60b00.tar.bz2 android-node-v8-f8d69911bef0ddd150d0f66f7a75b4655cf60b00.zip |
errors: use ERR_OUT_OF_RANGE for index errors
Remove ERR_INDEX_OUT_OF_RANGE in favor of ERR_OUT_OF_RANGE which is
capable of providing more detail. (In one instance, use
ERR_BUFFER_OUT_OF_BOUNDS which is more accurate in that one instance.)
PR-URL: https://github.com/nodejs/node/pull/22969
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-buffer-alloc.js | 5 | ||||
-rw-r--r-- | test/parallel/test-buffer-compare-offset.js | 2 | ||||
-rw-r--r-- | test/parallel/test-buffer-fill.js | 21 |
3 files changed, 15 insertions, 13 deletions
diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 023852b69a..5088e3c06f 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -1011,9 +1011,8 @@ common.expectsError(() => { const b = Buffer.alloc(1); a.copy(b, 0, 0x100000000, 0x100000001); }, { - code: 'ERR_INDEX_OUT_OF_RANGE', - type: RangeError, - message: 'Index out of range' + code: 'ERR_OUT_OF_RANGE', + type: RangeError }); // Unpooled buffer (replaces SlowBuffer) diff --git a/test/parallel/test-buffer-compare-offset.js b/test/parallel/test-buffer-compare-offset.js index 7f3121bef1..0fee87d710 100644 --- a/test/parallel/test-buffer-compare-offset.js +++ b/test/parallel/test-buffer-compare-offset.js @@ -57,7 +57,7 @@ assert.strictEqual(1, a.compare(b, Infinity, -Infinity)); // zero length target because default for targetEnd <= targetSource assert.strictEqual(1, a.compare(b, '0xff')); -const oor = common.expectsError({ code: 'ERR_INDEX_OUT_OF_RANGE' }, 7); +const oor = common.expectsError({ code: 'ERR_OUT_OF_RANGE' }, 7); assert.throws(() => a.compare(b, 0, 100, 0), oor); assert.throws(() => a.compare(b, 0, 1, 0, 100), oor); diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 4eef0edefc..3daaa91d8f 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -2,7 +2,7 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); -const { codes: { ERR_INDEX_OUT_OF_RANGE } } = require('internal/errors'); +const { codes: { ERR_OUT_OF_RANGE } } = require('internal/errors'); const SIZE = 28; const buf1 = Buffer.allocUnsafe(SIZE); @@ -173,7 +173,7 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, 1]), [0, 0, 0, 0]); ].forEach((args) => { common.expectsError( () => buf1.fill(...args), - { code: 'ERR_INDEX_OUT_OF_RANGE' } + { code: 'ERR_OUT_OF_RANGE' } ); }); @@ -237,7 +237,7 @@ function writeToFill(string, offset, end, encoding) { // Should never be reached. if (offset < 0 || end > buf2.length) - throw new ERR_INDEX_OUT_OF_RANGE(); + throw new ERR_OUT_OF_RANGE(); if (end <= offset) return buf2; @@ -276,10 +276,10 @@ function testBufs(string, offset, length, encoding) { // Make sure these throw. common.expectsError( () => Buffer.allocUnsafe(8).fill('a', -1), - { code: 'ERR_INDEX_OUT_OF_RANGE' }); + { code: 'ERR_OUT_OF_RANGE' }); common.expectsError( () => Buffer.allocUnsafe(8).fill('a', 0, 9), - { code: 'ERR_INDEX_OUT_OF_RANGE' }); + { code: 'ERR_OUT_OF_RANGE' }); // Make sure this doesn't hang indefinitely. Buffer.allocUnsafe(8).fill(''); @@ -333,6 +333,9 @@ assert.strictEqual( // Symbol.toPrimitive. { let elseWasLast = false; + const expectedErrorMessage = + 'The value of "end" is out of range. It must be >= 0 and <= 1. Received -1'; + common.expectsError(() => { let ctr = 0; const end = { @@ -350,9 +353,9 @@ assert.strictEqual( }; Buffer.alloc(1).fill(Buffer.alloc(1), 0, end); }, { - code: 'ERR_INDEX_OUT_OF_RANGE', + code: 'ERR_OUT_OF_RANGE', type: RangeError, - message: 'Index out of range' + message: expectedErrorMessage }); // Make sure -1 is making it to Buffer::Fill(). assert.ok(elseWasLast, @@ -373,9 +376,9 @@ common.expectsError(() => { }); buf.fill(''); }, { - code: 'ERR_INDEX_OUT_OF_RANGE', + code: 'ERR_BUFFER_OUT_OF_BOUNDS', type: RangeError, - message: 'Index out of range' + message: 'Attempt to write outside buffer bounds' }); assert.deepStrictEqual( |