Skip to content
16 changes: 16 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const experimentalWarnings = new SafeSet();

const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex


let uvBinding;

function lazyUv() {
if (!uvBinding) {
uvBinding = internalBinding('uv');
}
return uvBinding;
}

function removeColors(str) {
return StringPrototypeReplace(str, colorRegExp, '');
}
Expand Down Expand Up @@ -286,6 +296,11 @@ function getSystemErrorName(err) {
return entry ? entry[0] : `Unknown system error ${err}`;
}

function getSystemErrorMap() {
uvBinding = lazyUv();
return uvBinding.getErrorMap();
}

const kCustomPromisifiedSymbol = SymbolFor('nodejs.util.promisify.custom');
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');

Expand Down Expand Up @@ -443,6 +458,7 @@ module.exports = {
filterDuplicateStrings,
getConstructorOf,
getSystemErrorName,
getSystemErrorMap,
isError,
isInsideNodeModules,
join,
Expand Down
3 changes: 2 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const types = require('internal/util/types');
const {
deprecate,
getSystemErrorName: internalErrorName,
getSystemErrorMap,
promisify
} = require('internal/util');

Expand Down Expand Up @@ -244,7 +245,6 @@ function getSystemErrorName(err) {
}
return internalErrorName(err);
}

// Keep the `exports =` so that various functions can still be monkeypatched
module.exports = {
_errnoException: errnoException,
Expand All @@ -257,6 +257,7 @@ module.exports = {
format,
formatWithOptions,
getSystemErrorName,
getSystemErrorMap,
inherits,
inspect,
isArray: ArrayIsArray,
Expand Down