Skip to content

Commit cdc1171

Browse files
Trottjasnell
authored andcommitted
doc: fix errors in sample code comments
The errors thrown have changed in a few places. Update the comments to reflect the current errors. The `noAssert` option has been removed but it is still shown in sample code in a few places. Remove that sample code. PR-URL: #19963 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 90fc496 commit cdc1171

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

doc/api/buffer.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,10 +1525,7 @@ console.log(buf.readDoubleBE(0));
15251525
console.log(buf.readDoubleLE(0));
15261526
// Prints: 5.447603722011605e-270
15271527
console.log(buf.readDoubleLE(1));
1528-
// Throws an exception: RangeError: Index out of range
1529-
console.log(buf.readDoubleLE(1, true));
1530-
// Warning: reads passed end of buffer!
1531-
// This will result in a segmentation fault! Don't do this!
1528+
// Throws ERR_OUT_OF_RANGE
15321529
```
15331530

15341531
### buf.readFloatBE(offset)
@@ -1558,10 +1555,7 @@ console.log(buf.readFloatBE(0));
15581555
console.log(buf.readFloatLE(0));
15591556
// Prints: 1.539989614439558e-36
15601557
console.log(buf.readFloatLE(1));
1561-
// Throws an exception: RangeError: Index out of range
1562-
console.log(buf.readFloatLE(1, true));
1563-
// Warning: reads passed end of buffer!
1564-
// This will result in a segmentation fault! Don't do this!
1558+
// Throws ERR_OUT_OF_RANGE
15651559
```
15661560

15671561
### buf.readInt8(offset)
@@ -1590,7 +1584,7 @@ console.log(buf.readInt8(0));
15901584
console.log(buf.readInt8(1));
15911585
// Prints: 5
15921586
console.log(buf.readInt8(2));
1593-
// Throws an exception: RangeError: Index out of range
1587+
// Throws ERR_OUT_OF_RANGE
15941588
```
15951589

15961590
### buf.readInt16BE(offset)
@@ -1622,7 +1616,7 @@ console.log(buf.readInt16BE(0));
16221616
console.log(buf.readInt16LE(0));
16231617
// Prints: 1280
16241618
console.log(buf.readInt16LE(1));
1625-
// Throws an exception: RangeError: Index out of range
1619+
// Throws ERR_OUT_OF_RANGE
16261620
```
16271621

16281622
### buf.readInt32BE(offset)
@@ -1654,7 +1648,7 @@ console.log(buf.readInt32BE(0));
16541648
console.log(buf.readInt32LE(0));
16551649
// Prints: 83886080
16561650
console.log(buf.readInt32LE(1));
1657-
// Throws an exception: RangeError: Index out of range
1651+
// Throws ERR_OUT_OF_RANGE
16581652
```
16591653

16601654
### buf.readIntBE(offset, byteLength)
@@ -1686,9 +1680,9 @@ console.log(buf.readIntLE(0, 6).toString(16));
16861680
console.log(buf.readIntBE(0, 6).toString(16));
16871681
// Prints: 1234567890ab
16881682
console.log(buf.readIntBE(1, 6).toString(16));
1689-
// Throws ERR_INDEX_OUT_OF_RANGE:
1683+
// Throws ERR_INDEX_OUT_OF_RANGE
16901684
console.log(buf.readIntBE(1, 0).toString(16));
1691-
// Throws ERR_OUT_OF_RANGE:
1685+
// Throws ERR_OUT_OF_RANGE
16921686
```
16931687

16941688
### buf.readUInt8(offset)
@@ -1715,7 +1709,7 @@ console.log(buf.readUInt8(0));
17151709
console.log(buf.readUInt8(1));
17161710
// Prints: 254
17171711
console.log(buf.readUInt8(2));
1718-
// Throws an exception: RangeError: Index out of range
1712+
// Throws ERR_OUT_OF_RANGE
17191713
```
17201714

17211715
### buf.readUInt16BE(offset)
@@ -1749,7 +1743,7 @@ console.log(buf.readUInt16BE(1).toString(16));
17491743
console.log(buf.readUInt16LE(1).toString(16));
17501744
// Prints: 5634
17511745
console.log(buf.readUInt16LE(2).toString(16));
1752-
// Throws an exception: RangeError: Index out of range
1746+
// Throws ERR_OUT_OF_RANGE
17531747
```
17541748

17551749
### buf.readUInt32BE(offset)
@@ -1779,7 +1773,7 @@ console.log(buf.readUInt32BE(0).toString(16));
17791773
console.log(buf.readUInt32LE(0).toString(16));
17801774
// Prints: 78563412
17811775
console.log(buf.readUInt32LE(1).toString(16));
1782-
// Throws an exception: RangeError: Index out of range
1776+
// Throws ERR_OUT_OF_RANGE
17831777
```
17841778

17851779
### buf.readUIntBE(offset, byteLength)
@@ -1811,7 +1805,7 @@ console.log(buf.readUIntBE(0, 6).toString(16));
18111805
console.log(buf.readUIntLE(0, 6).toString(16));
18121806
// Prints: ab9078563412
18131807
console.log(buf.readUIntBE(1, 6).toString(16));
1814-
// Throws an exception: RangeError: Index out of range
1808+
// Throws ERR_OUT_OF_RANGE
18151809
```
18161810

18171811
### buf.slice([start[, end]])
@@ -1907,7 +1901,7 @@ console.log(buf1);
19071901
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
19081902

19091903
buf2.swap16();
1910-
// Throws an exception: RangeError: Buffer size must be a multiple of 16-bits
1904+
// Throws ERR_INVALID_BUFFER_SIZE
19111905
```
19121906

19131907
### buf.swap32()
@@ -1934,7 +1928,7 @@ console.log(buf1);
19341928
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
19351929

19361930
buf2.swap32();
1937-
// Throws an exception: RangeError: Buffer size must be a multiple of 32-bits
1931+
// Throws ERR_INVALID_BUFFER_SIZE
19381932
```
19391933

19401934
### buf.swap64()
@@ -1961,7 +1955,7 @@ console.log(buf1);
19611955
const buf2 = Buffer.from([0x1, 0x2, 0x3]);
19621956

19631957
buf2.swap64();
1964-
// Throws an exception: RangeError: Buffer size must be a multiple of 64-bits
1958+
// Throws ERR_INVALID_BUFFER_SIZE
19651959
```
19661960

19671961
Note that JavaScript cannot encode 64-bit integers. This method is intended

0 commit comments

Comments
 (0)