Skip to content

Commit dede0e1

Browse files
dnlupBethGriggs
authored andcommitted
lib: reduce usage of require('util')
Replace `require('util').inspect` and `require('util').format` with `require('util/internal/inspect').inspect` and `require('util/internal/inspect').format` in `lib/internal/errors.js`. PR-URL: #26782 Refs: #26546 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5d4c0db commit dede0e1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/internal/errors.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ function lazyInternalUtil() {
3232
return internalUtil;
3333
}
3434

35+
let internalUtilInspect = null;
36+
function lazyInternalUtilInspect() {
37+
if (!internalUtilInspect) {
38+
internalUtilInspect = require('internal/util/inspect');
39+
}
40+
return internalUtilInspect;
41+
}
42+
3543
let buffer;
3644
function lazyBuffer() {
3745
if (buffer === undefined)
@@ -260,7 +268,6 @@ function E(sym, val, def, ...otherClasses) {
260268
function getMessage(key, args, self) {
261269
const msg = messages.get(key);
262270

263-
if (util === undefined) util = require('util');
264271
if (assert === undefined) assert = require('internal/assert');
265272

266273
if (typeof msg === 'function') {
@@ -282,7 +289,7 @@ function getMessage(key, args, self) {
282289
return msg;
283290

284291
args.unshift(msg);
285-
return util.format.apply(null, args);
292+
return lazyInternalUtilInspect().format.apply(null, args);
286293
}
287294

288295
let uvBinding;
@@ -820,7 +827,7 @@ E('ERR_INVALID_ARG_TYPE',
820827
return msg;
821828
}, TypeError);
822829
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
823-
let inspected = util.inspect(value);
830+
let inspected = lazyInternalUtilInspect().inspect(value);
824831
if (inspected.length > 128) {
825832
inspected = `${inspected.slice(0, 128)}...`;
826833
}

0 commit comments

Comments
 (0)