Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion for getSystemErrorMap() implementation #38101

16 changes: 16 additions & 0 deletions lib/internal/util.js
Expand Up @@ -53,6 +53,16 @@ const experimentalWarnings = new SafeSet();

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


EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
let uvBinding;

function lazyUv() {
if (!uvBinding) {
uvBinding = internalBinding('uv');
}
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
return uvBinding;
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
}

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();
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
}
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved

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,
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
isError,
isInsideNodeModules,
join,
Expand Down
3 changes: 2 additions & 1 deletion lib/util.js
Expand Up @@ -68,6 +68,7 @@ const types = require('internal/util/types');
const {
deprecate,
getSystemErrorName: internalErrorName,
getSystemErrorMap,
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
promisify
} = require('internal/util');

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

EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
// 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,
EladKeyshawn marked this conversation as resolved.
Show resolved Hide resolved
inherits,
inspect,
isArray: ArrayIsArray,
Expand Down