From f8d69911bef0ddd150d0f66f7a75b4655cf60b00 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 19 Sep 2018 20:04:47 -0700 Subject: [PATCH] errors: use ERR_OUT_OF_RANGE for index errors Remove ERR_INDEX_OUT_OF_RANGE in favor of ERR_OUT_OF_RANGE which is capable of providing more detail. (In one instance, use ERR_BUFFER_OUT_OF_BOUNDS which is more accurate in that one instance.) PR-URL: https://github.com/nodejs/node/pull/22969 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Ruben Bridgewater Reviewed-By: Luigi Pinca Reviewed-By: Weijia Wang --- doc/api/buffer.md | 9 +- doc/api/errors.md | 13 ++- lib/buffer.js | 111 ++++++++++---------- lib/internal/errors.js | 1 - src/node_buffer.cc | 17 +-- src/node_errors.h | 10 +- test/parallel/test-buffer-alloc.js | 5 +- test/parallel/test-buffer-compare-offset.js | 2 +- test/parallel/test-buffer-fill.js | 21 ++-- 9 files changed, 104 insertions(+), 85 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 56999a1955d0a1..11f3795741b3d3 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -1085,7 +1085,7 @@ console.log(buf1.compare(buf2, 5, 6, 5)); // Prints: 1 ``` -[`ERR_INDEX_OUT_OF_RANGE`] is thrown if `targetStart < 0`, `sourceStart < 0`, +[`ERR_OUT_OF_RANGE`] is thrown if `targetStart < 0`, `sourceStart < 0`, `targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`. ### buf.copy(target[, targetStart[, sourceStart[, sourceEnd]]]) @@ -1197,6 +1197,9 @@ console.log(buf1.equals(buf3)); +A given index was out of the accepted range (e.g. negative offsets). + ### ERR_NAPI_CONS_PROTOTYPE_OBJECT