From 4aae313c116cfd2608c0799dad8869fe8f3776c3 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`. Refs: https://github.com/nodejs/node/issues/26546 --- 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;