diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 991af52fee5b95..17b10dab189133 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -63,6 +63,7 @@ function validateInteger(value, name) { } function validateInt32(value, name, min = -2147483648, max = 2147483647) { + // The defaults for min and max correspond to the limits of 32-bit integers. if (!isInt32(value)) { let err; if (typeof value !== 'number') { @@ -70,11 +71,14 @@ function validateInt32(value, name, min = -2147483648, max = 2147483647) { } else if (!Number.isInteger(value)) { err = new ERR_OUT_OF_RANGE(name, 'an integer', value); } else { - // 2 ** 31 === 2147483648 - err = new ERR_OUT_OF_RANGE(name, '> -2147483649 && < 2147483648', value); + err = new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); } Error.captureStackTrace(err, validateInt32); throw err; + } else if (value < min || value > max) { + const err = new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); + Error.captureStackTrace(err, validateInt32); + throw err; } }