From 3cb824170b8deb422f58c782d31c3bcdca5dd391 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 3 Jan 2024 20:35:53 -0400 Subject: sugar: showAggregate: pad siblings of aggregates for alignment --- src/util/sugar.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/util') diff --git a/src/util/sugar.js b/src/util/sugar.js index faf685b5..a447e6e7 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -720,7 +720,19 @@ export function showAggregate(topError, { helpfulTraceLines: ownHelpfulTraceLines, unhelpfulTraceLines: ownUnhelpfulTraceLines, }, - }) => { + }, index, apparentSiblings) => { + const subApparentSiblings = + (cause && errors + ? [cause, ...errors] + : cause + ? [cause] + : errors + ? errors + : []); + + const anythingHasErrorsThisLayer = + apparentSiblings.some(({errors}) => !empty(errors)); + const messagePart = message || `(no message)`; @@ -732,6 +744,8 @@ export function showAggregate(topError, { ? `[${kindPart}] ${messagePart}` : errors ? `[${messagePart}]` + : anythingHasErrorsThisLayer + ? ` ${messagePart}` : messagePart); if (showTraces || alwaysTrace) { @@ -764,7 +778,7 @@ export function showAggregate(topError, { const causePart = (cause - ? recursive(cause) + ? recursive(cause, 0, subApparentSiblings) .split('\n') .map((line, i) => i === 0 ? ` ${head1} ${line}` : ` ${bar1} ${line}`) .join('\n') @@ -776,7 +790,7 @@ export function showAggregate(topError, { const errorsPart = (errors ? errors - .map(error => recursive(error)) + .map((error, index) => recursive(error, index + 1, subApparentSiblings)) .flatMap(str => str.split('\n')) .map((line, i) => i === 0 ? ` ${head2} ${line}` : ` ${bar2} ${line}`) .join('\n') @@ -786,7 +800,7 @@ export function showAggregate(topError, { }; const structure = flattenErrorStructure(topError); - const message = recursive(structure); + const message = recursive(structure, 0, [structure]); if (print) { console.error(message); -- cgit 1.3.0-6-gf8a5