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

6 changes: 6 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ function uvErrmapGet(name) {
return MapPrototypeGet(uvBinding.errmap, name);
}

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

const captureLargerStackTrace = hideStackFrames(
function captureLargerStackTrace(err) {
userStackTraceLimit = Error.stackTraceLimit;
Expand Down Expand Up @@ -782,6 +787,7 @@ module.exports = {
isStackOverflowError,
connResetException,
uvErrmapGet,
uvGetFullErrMap,
uvException,
uvExceptionWithHostPort,
SystemError,
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const {
ERR_UNKNOWN_SIGNAL
},
uvErrmapGet,
uvGetFullErrMap,
overrideStackTrace,
} = require('internal/errors');
const { signals } = internalBinding('constants').os;
Expand Down Expand Up @@ -286,6 +287,10 @@ function getSystemErrorName(err) {
return entry ? entry[0] : `Unknown system error ${err}`;
}

function getSystemErrorMap() {
return uvGetFullErrMap();
}

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

Expand Down Expand Up @@ -443,6 +448,7 @@ module.exports = {
filterDuplicateStrings,
getConstructorOf,
getSystemErrorName,
getSystemErrorMap,
isError,
isInsideNodeModules,
join,
Expand Down
5 changes: 5 additions & 0 deletions 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: internalErrorMap,
promisify
} = require('internal/util');

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

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