From 077e7e0ce745f6f4bd48ca19f2a17ba0c11eacb5 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. Backport-PR-URL: https://github.com/nodejs/node/pull/23039 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 ec9651ec97c495..cfced8d9942d68 100644 --- a/lib/util.js +++ b/lib/util.js @@ -832,6 +832,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) { @@ -841,16 +842,17 @@ function formatRaw(ctx, value, recurseTimes) { } } } catch (err) { - return handleMaxCallStackSize(ctx, err, constructor, tag); + return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl); } ctx.seen.pop(); return reduceToSingleString(ctx, output, base, braces); } -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.]',