diff --git a/lib/internal/util.js b/lib/internal/util.js index 1e48eedfd59b48..3de8090cfa2618 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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}`; } diff --git a/lib/util.js b/lib/util.js index 4525792b2ec4c4..14c99bd454c8b0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -55,7 +55,7 @@ const { const { customInspectSymbol, deprecate, - getSystemErrorName, + getSystemErrorName: internalErrorName, getIdentificationOf, isError, promisify, @@ -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,