Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 902fc2f

Browse filesBrowse files
cjihrigBridgeAR
authored andcommitted
lib: consolidate lazyErrmapGet()
There are currently two implementations of this function. This commit removes the redundancy, and removes "lazy" from the name. PR-URL: #29285 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent fdfde05 commit 902fc2f
Copy full SHA for 902fc2f

File tree

Expand file treeCollapse file tree

2 files changed

+12
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-20
lines changed
Open diff view settings
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function lazyUv() {
327327
return uvBinding;
328328
}
329329

330-
function lazyErrmapGet(name) {
330+
function uvErrmapGet(name) {
331331
uvBinding = lazyUv();
332332
if (!uvBinding.errmap) {
333333
uvBinding.errmap = uvBinding.getErrorMap();
@@ -346,7 +346,7 @@ function lazyErrmapGet(name) {
346346
* @returns {Error}
347347
*/
348348
function uvException(ctx) {
349-
const [ code, uvmsg ] = lazyErrmapGet(ctx.errno);
349+
const [ code, uvmsg ] = uvErrmapGet(ctx.errno);
350350
let message = `${code}: ${ctx.message || uvmsg}, ${ctx.syscall}`;
351351

352352
let path;
@@ -404,7 +404,7 @@ function uvException(ctx) {
404404
* @returns {Error}
405405
*/
406406
function uvExceptionWithHostPort(err, syscall, address, port) {
407-
const [ code, uvmsg ] = lazyErrmapGet(err);
407+
const [ code, uvmsg ] = uvErrmapGet(err);
408408
const message = `${syscall} ${code}: ${uvmsg}`;
409409
let details = '';
410410

@@ -666,6 +666,7 @@ module.exports = {
666666
hideStackFrames,
667667
isStackOverflowError,
668668
connResetException,
669+
uvErrmapGet,
669670
uvException,
670671
uvExceptionWithHostPort,
671672
SystemError,
Collapse file

‎lib/internal/util.js‎

Copy file name to clipboardExpand all lines: lib/internal/util.js
+8-17Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use strict';
22

33
const { Object, Reflect } = primordials;
4-
54
const {
6-
ERR_INVALID_ARG_TYPE,
7-
ERR_NO_CRYPTO,
8-
ERR_UNKNOWN_SIGNAL
9-
} = require('internal/errors').codes;
5+
codes: {
6+
ERR_INVALID_ARG_TYPE,
7+
ERR_NO_CRYPTO,
8+
ERR_UNKNOWN_SIGNAL
9+
},
10+
uvErrmapGet
11+
} = require('internal/errors');
1012
const { signals } = internalBinding('constants').os;
1113
const {
1214
getHiddenValue,
@@ -244,19 +246,8 @@ function getConstructorOf(obj) {
244246
return null;
245247
}
246248

247-
let uvBinding;
248-
function lazyErrmapGet(name) {
249-
if (!uvBinding) {
250-
uvBinding = internalBinding('uv');
251-
}
252-
if (!uvBinding.errmap) {
253-
uvBinding.errmap = uvBinding.getErrorMap();
254-
}
255-
return uvBinding.errmap.get(name);
256-
}
257-
258249
function getSystemErrorName(err) {
259-
const entry = lazyErrmapGet(err);
250+
const entry = uvErrmapGet(err);
260251
return entry ? entry[0] : `Unknown system error ${err}`;
261252
}
262253

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.