Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 871e327

Browse filesBrowse files
arvind3157targos
authored andcommitted
test: fixed error message in test-buffer-read
PR-URL: #23957 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent da494ef commit 871e327
Copy full SHA for 871e327

File tree

Expand file treeCollapse file tree

1 file changed

+26
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-14
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-buffer-read.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-read.js
+26-14Lines changed: 26 additions & 14 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.