Skip to content

lib: consolidate lazyErrmapGet() #29285

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function lazyUv() {
return uvBinding;
}

function lazyErrmapGet(name) {
function uvErrmapGet(name) {
uvBinding = lazyUv();
if (!uvBinding.errmap) {
uvBinding.errmap = uvBinding.getErrorMap();
Expand All @@ -346,7 +346,7 @@ function lazyErrmapGet(name) {
* @returns {Error}
*/
function uvException(ctx) {
const [ code, uvmsg ] = lazyErrmapGet(ctx.errno);
const [ code, uvmsg ] = uvErrmapGet(ctx.errno);
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;

let path;
Expand Down Expand Up @@ -404,7 +404,7 @@ function uvException(ctx) {
* @returns {Error}
*/
function uvExceptionWithHostPort(err, syscall, address, port) {
const [ code, uvmsg ] = lazyErrmapGet(err);
const [ code, uvmsg ] = uvErrmapGet(err);
const message = `${syscall} ${code}: ${uvmsg}`;
let details = '';

Expand Down Expand Up @@ -671,6 +671,7 @@ module.exports = {
hideStackFrames,
isStackOverflowError,
connResetException,
uvErrmapGet,
uvException,
uvExceptionWithHostPort,
SystemError,
Expand Down
25 changes: 8 additions & 17 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

const { Object, Reflect } = primordials;

const {
ERR_INVALID_ARG_TYPE,
ERR_NO_CRYPTO,
ERR_UNKNOWN_SIGNAL
} = require('internal/errors').codes;
codes: {
ERR_INVALID_ARG_TYPE,
ERR_NO_CRYPTO,
ERR_UNKNOWN_SIGNAL
},
uvErrmapGet
} = require('internal/errors');
const { signals } = internalBinding('constants').os;
const {
getHiddenValue,
Expand Down Expand Up @@ -244,19 +246,8 @@ function getConstructorOf(obj) {
return null;
}

let uvBinding;
function lazyErrmapGet(name) {
if (!uvBinding) {
uvBinding = internalBinding('uv');
}
if (!uvBinding.errmap) {
uvBinding.errmap = uvBinding.getErrorMap();
}
return uvBinding.errmap.get(name);
}

function getSystemErrorName(err) {
const entry = lazyErrmapGet(err);
const entry = uvErrmapGet(err);
return entry ? entry[0] : `Unknown system error ${err}`;
}

Expand Down