Skip to content

Commit 5f3b850

Browse files
dnluptargos
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 <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fef2a54 commit 5f3b850

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/internal/errors.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ function lazyInternalUtil() {
3030
return internalUtil;
3131
}
3232

33+
let internalUtilInspect = null;
34+
function lazyInternalUtilInspect() {
35+
if (!internalUtilInspect) {
36+
internalUtilInspect = require('internal/util/inspect');
37+
}
38+
return internalUtilInspect;
39+
}
40+
3341
let buffer;
3442
function lazyBuffer() {
3543
if (buffer === undefined)
@@ -220,7 +228,6 @@ function E(sym, val, def, ...otherClasses) {
220228
function getMessage(key, args, self) {
221229
const msg = messages.get(key);
222230

223-
if (util === undefined) util = require('util');
224231
if (assert === undefined) assert = require('internal/assert');
225232

226233
if (typeof msg === 'function') {
@@ -242,7 +249,7 @@ function getMessage(key, args, self) {
242249
return msg;
243250

244251
args.unshift(msg);
245-
return util.format.apply(null, args);
252+
return lazyInternalUtilInspect().format.apply(null, args);
246253
}
247254

248255
let uvBinding;
@@ -773,7 +780,7 @@ E('ERR_INVALID_ARG_TYPE',
773780
return msg;
774781
}, TypeError);
775782
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
776-
let inspected = util.inspect(value);
783+
let inspected = lazyInternalUtilInspect().inspect(value);
777784
if (inspected.length > 128) {
778785
inspected = `${inspected.slice(0, 128)}...`;
779786
}

0 commit comments

Comments
 (0)