« get me outta code hell

sugar: showAggregate: pad siblings of aggregates for alignment - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-03 20:35:53 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-03 20:35:53 -0400
commit3cb824170b8deb422f58c782d31c3bcdca5dd391 (patch)
treefda39b6a6558193efb9c8be25c9bf53f5101502e /src/util
parent5c48511052b8603b7077780e22f893f4c0160c74 (diff)
sugar: showAggregate: pad siblings of aggregates for alignment
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sugar.js22
1 files changed, 18 insertions, 4 deletions
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);