mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 18:44:40 +00:00
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: https://github.com/nodejs/node/pull/26782 Refs: https://github.com/nodejs/node/issues/26546 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
51256e5d78
commit
b51a546488
@ -32,6 +32,14 @@ function lazyInternalUtil() {
|
|||||||
return internalUtil;
|
return internalUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let internalUtilInspect = null;
|
||||||
|
function lazyInternalUtilInspect() {
|
||||||
|
if (!internalUtilInspect) {
|
||||||
|
internalUtilInspect = require('internal/util/inspect');
|
||||||
|
}
|
||||||
|
return internalUtilInspect;
|
||||||
|
}
|
||||||
|
|
||||||
let buffer;
|
let buffer;
|
||||||
function lazyBuffer() {
|
function lazyBuffer() {
|
||||||
if (buffer === undefined)
|
if (buffer === undefined)
|
||||||
@ -260,7 +268,6 @@ function E(sym, val, def, ...otherClasses) {
|
|||||||
function getMessage(key, args, self) {
|
function getMessage(key, args, self) {
|
||||||
const msg = messages.get(key);
|
const msg = messages.get(key);
|
||||||
|
|
||||||
if (util === undefined) util = require('util');
|
|
||||||
if (assert === undefined) assert = require('internal/assert');
|
if (assert === undefined) assert = require('internal/assert');
|
||||||
|
|
||||||
if (typeof msg === 'function') {
|
if (typeof msg === 'function') {
|
||||||
@ -282,7 +289,7 @@ function getMessage(key, args, self) {
|
|||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
args.unshift(msg);
|
args.unshift(msg);
|
||||||
return util.format.apply(null, args);
|
return lazyInternalUtilInspect().format.apply(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
let uvBinding;
|
let uvBinding;
|
||||||
@ -820,7 +827,7 @@ E('ERR_INVALID_ARG_TYPE',
|
|||||||
return msg;
|
return msg;
|
||||||
}, TypeError);
|
}, TypeError);
|
||||||
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
|
E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
|
||||||
let inspected = util.inspect(value);
|
let inspected = lazyInternalUtilInspect().inspect(value);
|
||||||
if (inspected.length > 128) {
|
if (inspected.length > 128) {
|
||||||
inspected = `${inspected.slice(0, 128)}...`;
|
inspected = `${inspected.slice(0, 128)}...`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user