« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/sugar.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/sugar.js')
-rw-r--r--src/util/sugar.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/util/sugar.js b/src/util/sugar.js
index d6bc3df..c8f1706 100644
--- a/src/util/sugar.js
+++ b/src/util/sugar.js
@@ -350,19 +350,28 @@ export function _withAggregate(mode, aggregateOpts, fn) {
     }
 }
 
-export function showAggregate(topError, {pathToFile = p => p} = {}) {
+export function showAggregate(topError, {
+    pathToFile = p => p,
+    showTraces = true
+} = {}) {
     const recursive = (error, {level}) => {
-        const stackLines = error.stack?.split('\n');
-        const stackLine = stackLines?.find(line =>
-            line.trim().startsWith('at')
-            && !line.includes('sugar')
-            && !line.includes('node:internal')
-            && !line.includes('<anonymous>'));
-        const tracePart = (stackLine
-            ? '- ' + stackLine.trim().replace(/file:\/\/(.*\.js)/, (match, pathname) => pathToFile(pathname))
-            : '(no stack trace)');
-
-        const header = `[${error.constructor.name || 'unnamed'}] ${error.message || '(no message)'} ${color.dim(tracePart)}`;
+        let header = (showTraces
+            ? `[${error.constructor.name || 'unnamed'}] ${error.message || '(no message)'}`
+            : (error instanceof AggregateError
+                ? `[${error.message || '(no message)'}]`
+                : error.message || '(no message)'));
+        if (showTraces) {
+            const stackLines = error.stack?.split('\n');
+            const stackLine = stackLines?.find(line =>
+                line.trim().startsWith('at')
+                && !line.includes('sugar')
+                && !line.includes('node:internal')
+                && !line.includes('<anonymous>'));
+            const tracePart = (stackLine
+                ? '- ' + stackLine.trim().replace(/file:\/\/(.*\.js)/, (match, pathname) => pathToFile(pathname))
+                : '(no stack trace)');
+            header += ` ${color.dim(tracePart)}`;
+        }
         const bar = (level % 2 === 0
             ? '\u2502'
             : color.dim('\u254e'));