From 9a5c1495b1caf36bdea2cc8d51d2980cc989410d Mon Sep 17 00:00:00 2001 From: dnlup Date: Fri, 22 Mar 2019 18:02:07 +0100 Subject: [PATCH] errors: remove usage of require('util') Remove internal usage of `require('util').inspect`. PR-URL: https://github.com/nodejs/node/pull/26781 Refs: https://github.com/nodejs/node/issues/26546 Reviewed-By: Ruben Bridgewater Reviewed-By: Daniel Bevenius --- lib/internal/error-serdes.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/internal/error-serdes.js b/lib/internal/error-serdes.js index 1fed04f0a9864f..1d0c742dc435d3 100644 --- a/lib/internal/error-serdes.js +++ b/lib/internal/error-serdes.js @@ -77,11 +77,12 @@ function GetName(object) { return desc && desc.value; } -let util; -function lazyUtil() { - if (!util) - util = require('util'); - return util; +let internalUtilInspect; +function inspect(...args) { + if (!internalUtilInspect) { + internalUtilInspect = require('internal/util/inspect'); + } + return internalUtilInspect.inspect(...args); } function serializeError(error) { @@ -106,7 +107,7 @@ function serializeError(error) { return Buffer.concat([Buffer.from([kSerializedObject]), serialized]); } catch {} return Buffer.concat([Buffer.from([kInspectedError]), - Buffer.from(lazyUtil().inspect(error), 'utf8')]); + Buffer.from(inspect(error), 'utf8')]); } function deserializeError(error) {