From 6dca62b28d3432c11fedc13f3942125097cd3ec5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 12 Apr 2018 11:10:46 -0700 Subject: [PATCH] doc: include error code in buffer documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/19982 Reviewed-By: Vse Mozhet Byt Reviewed-By: James M Snell Reviewed-By: Beth Griggs Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Trivikram Kamat --- doc/api/buffer.md | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index e0f2e812f32..b971021416a 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -442,9 +442,9 @@ changes: * `size` {integer} The desired length of the new `Buffer`. -Allocates a new `Buffer` of `size` bytes. If the `size` is larger than -[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be -thrown. A zero-length `Buffer` will be created if `size` is 0. +Allocates a new `Buffer` of `size` bytes. If `size` is larger than +[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is +thrown. A zero-length `Buffer` is created if `size` is 0. Prior to Node.js 8.0.0, the underlying memory for `Buffer` instances created in this way is *not initialized*. The contents of a newly created @@ -530,9 +530,9 @@ console.log(buf); // Prints: ``` -Allocates a new `Buffer` of `size` bytes. If the `size` is larger than -[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be -thrown. A zero-length `Buffer` will be created if `size` is 0. +Allocates a new `Buffer` of `size` bytes. If `size` is larger than +[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is +thrown. A zero-length `Buffer` is created if `size` is 0. If `fill` is specified, the allocated `Buffer` will be initialized by calling [`buf.fill(fill)`][`buf.fill()`]. @@ -571,9 +571,9 @@ changes: * `size` {integer} The desired length of the new `Buffer`. -Allocates a new `Buffer` of `size` bytes. If the `size` is larger than -[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be -thrown. A zero-length `Buffer` will be created if `size` is 0. +Allocates a new `Buffer` of `size` bytes. If `size` is larger than +[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is +thrown. A zero-length `Buffer` is created if `size` is 0. The underlying memory for `Buffer` instances created in this way is *not initialized*. The contents of the newly created `Buffer` are unknown and @@ -615,9 +615,9 @@ added: v5.12.0 * `size` {integer} The desired length of the new `Buffer`. -Allocates a new `Buffer` of `size` bytes. If the `size` is larger than -[`buffer.constants.MAX_LENGTH`] or smaller than 0, a [`RangeError`] will be -thrown. A zero-length `Buffer` will be created if `size` is 0. +Allocates a new `Buffer` of `size` bytes. If `size` is larger than +[`buffer.constants.MAX_LENGTH`] or smaller than 0, [`ERR_INVALID_OPT_VALUE`] is +thrown. A zero-length `Buffer` is created if `size` is 0. The underlying memory for `Buffer` instances created in this way is *not initialized*. The contents of the newly created `Buffer` are unknown and @@ -1058,8 +1058,8 @@ console.log(buf1.compare(buf2, 5, 6, 5)); // Prints: 1 ``` -A `RangeError` will be thrown if: `targetStart < 0`, `sourceStart < 0`, -`targetEnd > target.byteLength` or `sourceEnd > source.byteLength`. +[`ERR_INDEX_OUT_OF_RANGE`] is thrown if `targetStart < 0`, `sourceStart < 0`, +`targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`. ### buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]])