« get me outta code hell

nicer looking showAggregate output - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-01-29 10:58:59 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-01-29 10:58:59 -0400
commitdccb3cd1312cfa9c2ea86eef6833a63b778de157 (patch)
treee29269a2a8e33d8168e7080f8eba41ff10dab93f
parentdbd9a1a4a37d4476d1eab9a73774fef488e6cefb (diff)
nicer looking showAggregate output
-rw-r--r--src/util/sugar.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index 8e40adeb..f5d1d29d 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -356,7 +356,7 @@ export function _withAggregate(mode, aggregateOpts, fn) {
 }
 
 export function showAggregate(topError, {pathToFile = null} = {}) {
-    const recursive = error => {
+    const recursive = (error, {level}) => {
         const stackLines = error.stack?.split('\n');
         const stackLine = stackLines?.find(line =>
             line.trim().startsWith('at')
@@ -367,17 +367,25 @@ export function showAggregate(topError, {pathToFile = null} = {}) {
             : '(no stack trace)');
 
         const header = `[${error.constructor.name || 'unnamed'}] ${error.message || '(no message)'} ${color.dim(tracePart)}`;
+        const bar = (level % 2 === 0
+            ? '\u2502'
+            : color.dim('\u254e'));
+        const head = (level % 2 === 0
+            ? '\u257f'
+            : color.dim('\u257f'));
 
         if (error instanceof AggregateError) {
             return header + '\n' + (error.errors
-                .map(recursive)
+                .map(error => recursive(error, {level: level + 1}))
                 .flatMap(str => str.split('\n'))
-                .map(line => ` | ` + line)
+                .map((line, i, lines) => (i === 0
+                    ? ` ${head} ${line}`
+                    : ` ${bar} ${line}`))
                 .join('\n'));
         } else {
             return header;
         }
     };
 
-    console.error(recursive(topError));
+    console.error(recursive(topError, {level: 0}));
 }