From 66520afdb8b4e3a86cf93836fc5e0b783113ef1c 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/19191 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 d915a699b54717..2d408bbbb68016 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -202,11 +202,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 45f580d08f4d72..1379eb3f31a9d2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -50,7 +50,7 @@ const { customInspectSymbol, deprecate, getConstructorOf, - getSystemErrorName, + getSystemErrorName: internalErrorName, isError, promisify, join @@ -1065,6 +1065,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,