Skip to content

Commit

Permalink
crypto: improve invalid arg type message for randomInt()
Browse files Browse the repository at this point in the history
Use "must be a safe integer" rather than "must be safe integer". I
believe the former is more easily understood/clear.

PR-URL: #35089
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
Trott authored and ruyadorno committed Sep 17, 2020
1 parent 3573545 commit 1bb0ed3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-crypto-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`,
};

Expand Down Expand Up @@ -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)}`,
}
);
Expand All @@ -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)}`,
}
);
Expand Down

0 comments on commit 1bb0ed3

Please sign in to comment.