From ed1c51a9440210b7118515399c162d8f09f09a6d 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 895133bc8f79cf..b907842c3896ff 100644 --- a/lib/internal/error-serdes.js +++ b/lib/internal/error-serdes.js @@ -76,11 +76,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); } let serialize; @@ -107,7 +108,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')]); } let deserialize;