Skip to content

Commit

Permalink
util: fix indentationLvl when exceeding max call stack size
Browse files Browse the repository at this point in the history
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: #23039
PR-URL: #22787
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and targos committed Sep 24, 2018
1 parent 5a13e66 commit 077e7e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.]',
Expand Down

0 comments on commit 077e7e0

Please sign in to comment.