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: nodejs#35089
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
Trott authored and joesepi committed Oct 22, 2020
1 parent 2f88f4b commit 964e640
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 964e640

Please sign in to comment.