Skip to content

Commit e35f671

Browse files
arvind3157Trott
authored andcommitted
test: fixed error message in test-buffer-read
PR-URL: #23957 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent c515e5c commit e35f671

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

test/parallel/test-buffer-read.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,46 @@ read(buf, 'readUInt32LE', [1], 0xcfea48fd);
5151
read(buf, 'readUIntBE', [2, 2], 0x48ea);
5252
read(buf, 'readUIntLE', [2, 2], 0xea48);
5353

54+
// Error name and message
55+
const OOR_ERROR =
56+
{
57+
name: 'RangeError [ERR_OUT_OF_RANGE]'
58+
};
59+
60+
const OOB_ERROR =
61+
{
62+
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
63+
message: 'Attempt to write outside buffer bounds'
64+
};
65+
5466
// Attempt to overflow buffers, similar to previous bug in array buffers
55-
assert.throws(() => Buffer.allocUnsafe(8).readFloatBE(0xffffffff),
56-
RangeError);
57-
assert.throws(() => Buffer.allocUnsafe(8).readFloatLE(0xffffffff),
58-
RangeError);
67+
assert.throws(
68+
() => Buffer.allocUnsafe(8).readFloatBE(0xffffffff), OOR_ERROR);
69+
70+
assert.throws(
71+
() => Buffer.allocUnsafe(8).readFloatLE(0xffffffff), OOR_ERROR);
5972

6073
// Ensure negative values can't get past offset
61-
assert.throws(() => Buffer.allocUnsafe(8).readFloatBE(-1), RangeError);
62-
assert.throws(() => Buffer.allocUnsafe(8).readFloatLE(-1), RangeError);
74+
assert.throws(
75+
() => Buffer.allocUnsafe(8).readFloatBE(-1), OOR_ERROR);
76+
assert.throws(
77+
() => Buffer.allocUnsafe(8).readFloatLE(-1), OOR_ERROR);
6378

6479
// Offset checks
6580
{
6681
const buf = Buffer.allocUnsafe(0);
6782

68-
assert.throws(() => buf.readUInt8(0), RangeError);
69-
assert.throws(() => buf.readInt8(0), RangeError);
83+
assert.throws(
84+
() => buf.readUInt8(0), OOB_ERROR);
85+
assert.throws(
86+
() => buf.readInt8(0), OOB_ERROR);
7087
}
7188

7289
[16, 32].forEach((bit) => {
7390
const buf = Buffer.allocUnsafe(bit / 8 - 1);
7491
[`Int${bit}B`, `Int${bit}L`, `UInt${bit}B`, `UInt${bit}L`].forEach((fn) => {
7592
assert.throws(
76-
() => buf[`read${fn}E`](0),
77-
{
78-
name: 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]',
79-
message: 'Attempt to write outside buffer bounds'
80-
}
81-
);
93+
() => buf[`read${fn}E`](0), OOB_ERROR);
8294
});
8395
});
8496

0 commit comments

Comments
 (0)