diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 997e4fd2299cdb..b00886f5e680ba 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -668,8 +668,10 @@ void StringWrite(const FunctionCallbackInfo& args) { size_t max_length; THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[1], 0, &offset)); - if (offset > ts_obj_length) - return env->ThrowRangeError("Offset is out of bounds"); + if (offset > ts_obj_length) { + return node::THROW_ERR_BUFFER_OUT_OF_BOUNDS( + env, "\"offset\" is outside of buffer bounds"); + } THROW_AND_RETURN_IF_OOB(ParseArrayIndex(args[2], ts_obj_length - offset, &max_length)); diff --git a/src/node_errors.h b/src/node_errors.h index 1ebedc2fcb5a9b..fadbdbe37408b1 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -17,6 +17,7 @@ namespace node { // a `Local` containing the TypeError with proper code and message #define ERRORS_WITH_CODE(V) \ + V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \ V(ERR_INDEX_OUT_OF_RANGE, RangeError) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ V(ERR_MEMORY_ALLOCATION_FAILED, Error) \