Skip to content

Commit b806b04

Browse files
Trottjasnell
authored andcommitted
doc: include error code in buffer documentation
Replace mentions of `RangeError` with the specific error code (e.g., `ERR_INVALID_OPT_VALUE`). Minor improvements to nearby text (wrap at 80 chars, serial comma, remove unnecessary articles, use present tense consistently). PR-URL: #19982 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent b40efa4 commit b806b04

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

doc/api/buffer.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ changes:
442442
443443
* `size` {integer} The desired length of the new `Buffer`.
444444

445-
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
446-
[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be
447-
thrown. A zero-length `Buffer` will be created if `size` is 0.
445+
Allocates a new `Buffer` of `size` bytes. If `size` is larger than
446+
[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is
447+
thrown. A zero-length `Buffer` is created if `size` is 0.
448448

449449
Prior to Node.js 8.0.0, the underlying memory for `Buffer` instances
450450
created in this way is *not initialized*. The contents of a newly created
@@ -530,9 +530,9 @@ console.log(buf);
530530
// Prints: <Buffer 00 00 00 00 00>
531531
```
532532

533-
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
534-
[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be
535-
thrown. A zero-length `Buffer` will be created if `size` is 0.
533+
Allocates a new `Buffer` of `size` bytes. If `size` is larger than
534+
[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is
535+
thrown. A zero-length `Buffer` is created if `size` is 0.
536536

537537
If `fill` is specified, the allocated `Buffer` will be initialized by calling
538538
[`buf.fill(fill)`][`buf.fill()`].
@@ -571,9 +571,9 @@ changes:
571571

572572
* `size` {integer} The desired length of the new `Buffer`.
573573

574-
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
575-
[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be
576-
thrown. A zero-length `Buffer` will be created if `size` is 0.
574+
Allocates a new `Buffer` of `size` bytes. If `size` is larger than
575+
[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is
576+
thrown. A zero-length `Buffer` is created if `size` is 0.
577577

578578
The underlying memory for `Buffer` instances created in this way is *not
579579
initialized*. The contents of the newly created `Buffer` are unknown and
@@ -615,9 +615,9 @@ added: v5.12.0
615615

616616
* `size` {integer} The desired length of the new `Buffer`.
617617

618-
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
619-
[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be
620-
thrown. A zero-length `Buffer` will be created if `size` is 0.
618+
Allocates a new `Buffer` of `size` bytes. If `size` is larger than
619+
[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is
620+
thrown. A zero-length `Buffer` is created if `size` is 0.
621621

622622
The underlying memory for `Buffer` instances created in this way is *not
623623
initialized*. The contents of the newly created `Buffer` are unknown and
@@ -1058,8 +1058,8 @@ console.log(buf1.compare(buf2, 5, 6, 5));
10581058
// Prints: 1
10591059
```
10601060

1061-
A `RangeError` will be thrown if: `targetStart < 0`, `sourceStart < 0`,
1062-
`targetEnd > target.byteLength` or `sourceEnd > source.byteLength`.
1061+
[`ERR_INDEX_OUT_OF_RANGE`] is thrown if `targetStart < 0`, `sourceStart < 0`,
1062+
`targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
10631063

10641064
### buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])
10651065
<!-- YAML
@@ -1884,8 +1884,9 @@ added: v5.10.0
18841884

18851885
* Returns: {Buffer} A reference to `buf`.
18861886

1887-
Interprets `buf` as an array of unsigned 16-bit integers and swaps the byte-order
1888-
*in-place*. Throws a `RangeError` if [`buf.length`] is not a multiple of 2.
1887+
Interprets `buf` as an array of unsigned 16-bit integers and swaps the
1888+
byte-order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
1889+
not a multiple of 2.
18891890

18901891
```js
18911892
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
@@ -1911,8 +1912,9 @@ added: v5.10.0
19111912

19121913
* Returns: {Buffer} A reference to `buf`.
19131914

1914-
Interprets `buf` as an array of unsigned 32-bit integers and swaps the byte-order
1915-
*in-place*. Throws a `RangeError` if [`buf.length`] is not a multiple of 4.
1915+
Interprets `buf` as an array of unsigned 32-bit integers and swaps the
1916+
byte-order *in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is
1917+
not a multiple of 4.
19161918

19171919
```js
19181920
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
@@ -1938,8 +1940,9 @@ added: v6.3.0
19381940

19391941
* Returns: {Buffer} A reference to `buf`.
19401942

1941-
Interprets `buf` as an array of 64-bit numbers and swaps the byte-order *in-place*.
1942-
Throws a `RangeError` if [`buf.length`] is not a multiple of 8.
1943+
Interprets `buf` as an array of 64-bit numbers and swaps the byte-order
1944+
*in-place*. Throws [`ERR_INVALID_BUFFER_SIZE`] if [`buf.length`] is not a
1945+
multiple of 8.
19431946

19441947
```js
19451948
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
@@ -2539,9 +2542,9 @@ deprecated: v6.0.0
25392542
25402543
* `size` {integer} The desired length of the new `SlowBuffer`.
25412544

2542-
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
2543-
[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be
2544-
thrown. A zero-length `Buffer` will be created if `size` is 0.
2545+
Allocates a new `Buffer` of `size` bytes. If `size` is larger than
2546+
[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is
2547+
thrown. A zero-length `Buffer` is created if `size` is 0.
25452548

25462549
The underlying memory for `SlowBuffer` instances is *not initialized*. The
25472550
contents of a newly created `SlowBuffer` are unknown and may contain sensitive
@@ -2605,8 +2608,10 @@ This value may depend on the JS engine that is being used.
26052608
[`Buffer.from(string)`]: #buffer_class_method_buffer_from_string_encoding
26062609
[`Buffer.poolSize`]: #buffer_class_property_buffer_poolsize
26072610
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
2611+
[`ERR_INDEX_OUT_OF_RANGE`]: errors.html#ERR_INDEX_OUT_OF_RANGE
2612+
[`ERR_INVALID_BUFFER_SIZE`]: errors.html#ERR_INVALID_BUFFER_SIZE
2613+
[`ERR_INVALID_OPT_VALUE`]: errors.html#ERR_INVALID_OPT_VALUE
26082614
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
2609-
[`RangeError`]: errors.html#errors_class_rangeerror
26102615
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
26112616
[`String#indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
26122617
[`String#lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf

0 commit comments

Comments
 (0)