From 08d983c3b9c8c47ad3cf2b8f8ba0ffdfcaf875f6 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Mon, 10 Sep 2018 08:16:12 +0200 Subject: [PATCH] util: fix indentationLvl when exceeding max call stack size The inspection indentation level was not always reset to it's former value in case the maximum call stack size was exceeded. PR-URL: https://github.com/nodejs/node/pull/22787 Reviewed-By: James M Snell --- lib/util.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/util.js b/lib/util.js index 985f455e5dc455..89c86cb7fd0050 100644 --- a/lib/util.js +++ b/lib/util.js @@ -880,6 +880,7 @@ function formatRaw(ctx, value, recurseTimes) { ctx.seen.push(value); let output; + const indentationLvl = ctx.indentationLvl; try { output = formatter(ctx, value, recurseTimes, keys); if (skip === false) { @@ -889,7 +890,7 @@ function formatRaw(ctx, value, recurseTimes) { } } } catch (err) { - return handleMaxCallStackSize(ctx, err, constructor, tag); + return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl); } ctx.seen.pop(); @@ -910,9 +911,10 @@ function formatRaw(ctx, value, recurseTimes) { return res; } -function handleMaxCallStackSize(ctx, err, constructor, tag) { +function handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl) { if (errors.isStackOverflowError(err)) { ctx.seen.pop(); + ctx.indentationLvl = indentationLvl; return ctx.stylize( `[${constructor || tag || 'Object'}: Inspection interrupted ` + 'prematurely. Maximum call stack size exceeded.]',