Skip to content

Commit

Permalink
util: skip type checks in internal getSystemErrorName
Browse files Browse the repository at this point in the history
PR-URL: #18546
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Feb 7, 2018
1 parent bff5d5b commit 12ae334
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 0 additions & 8 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,6 @@ function getConstructorOf(obj) {
}

function getSystemErrorName(err) {
if (typeof err !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', 'number', err);
}
if (err >= 0 || !Number.isSafeInteger(err)) {
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'err',
'a negative integer', err);
}

const entry = errmap.get(err);
return entry ? entry[0] : `Unknown system error ${err}`;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const {
const {
customInspectSymbol,
deprecate,
getSystemErrorName,
getSystemErrorName: internalErrorName,
getIdentificationOf,
isError,
promisify,
Expand Down Expand Up @@ -1139,6 +1139,17 @@ function callbackify(original) {
return callbackified;
}

function getSystemErrorName(err) {
if (typeof err !== 'number') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', 'number', err);
}
if (err >= 0 || !Number.isSafeInteger(err)) {
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'err',
'a negative integer', err);
}
return internalErrorName(err);
}

// Keep the `exports =` so that various functions can still be monkeypatched
module.exports = exports = {
_errnoException,
Expand Down

0 comments on commit 12ae334

Please sign in to comment.