From f1f180d80cb6cde27c78832adf50029f878eb2f8 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 3 Feb 2018 17:30:48 +0800 Subject: [PATCH] util: skip type checks in internal getSystemErrorName Backport-PR-URL: https://github.com/nodejs/node/pull/18916 PR-URL: https://github.com/nodejs/node/pull/18546 Reviewed-By: James M Snell --- lib/internal/util.js | 5 ----- lib/util.js | 10 +++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 51505f6845f3c7..fd481450bc246d 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -208,11 +208,6 @@ function getConstructorOf(obj) { } function getSystemErrorName(err) { - if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { - throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', - 'negative number'); - } - const entry = errmap.get(err); return entry ? entry[0] : `Unknown system error ${err}`; } diff --git a/lib/util.js b/lib/util.js index ac2c998ccab627..539608c4164893 100644 --- a/lib/util.js +++ b/lib/util.js @@ -54,7 +54,7 @@ const { customInspectSymbol, deprecate, getConstructorOf, - getSystemErrorName, + getSystemErrorName: internalErrorName, isError, promisify, join, @@ -1071,6 +1071,14 @@ function callbackify(original) { return callbackified; } +function getSystemErrorName(err) { + if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', + 'negative number'); + } + return internalErrorName(err); +} + // Keep the `exports =` so that various functions can still be monkeypatched module.exports = exports = { _errnoException,