From 964e640a5f8301a82012e73ec224e6a84904e0dd Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 7 Sep 2020 07:44:46 -0700 Subject: [PATCH] crypto: improve invalid arg type message for randomInt() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use "must be a safe integer" rather than "must be safe integer". I believe the former is more easily understood/clear. PR-URL: https://github.com/nodejs/node/pull/35089 Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen --- lib/internal/crypto/random.js | 4 ++-- test/parallel/test-crypto-random.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 99d4a2bd89f8dd..9e0500ea3a67bb 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -144,10 +144,10 @@ function randomInt(min, max, callback) { throw new ERR_INVALID_CALLBACK(callback); } if (!NumberIsSafeInteger(min)) { - throw new ERR_INVALID_ARG_TYPE('min', 'safe integer', min); + throw new ERR_INVALID_ARG_TYPE('min', 'a safe integer', min); } if (!NumberIsSafeInteger(max)) { - throw new ERR_INVALID_ARG_TYPE('max', 'safe integer', max); + throw new ERR_INVALID_ARG_TYPE('max', 'a safe integer', max); } if (max <= min) { throw new ERR_OUT_OF_RANGE( diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 8864b179871137..e079bc9de2c7d9 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -394,13 +394,13 @@ assert.throws( const invalidMinError = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "min" argument must be safe integer.' + + message: 'The "min" argument must be a safe integer.' + `${common.invalidArgTypeHelper(i)}`, }; const invalidMaxError = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "max" argument must be safe integer.' + + message: 'The "max" argument must be a safe integer.' + `${common.invalidArgTypeHelper(i)}`, }; @@ -441,7 +441,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "min" argument must be safe integer.' + + message: 'The "min" argument must be a safe integer.' + `${common.invalidArgTypeHelper(minInt - 1)}`, } ); @@ -451,7 +451,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "max" argument must be safe integer.' + + message: 'The "max" argument must be a safe integer.' + `${common.invalidArgTypeHelper(maxInt + 1)}`, } );