From dccb3cd1312cfa9c2ea86eef6833a63b778de157 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 29 Jan 2022 10:58:59 -0400 Subject: nicer looking showAggregate output --- src/util/sugar.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/util/sugar.js b/src/util/sugar.js index 8e40ade..f5d1d29 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})); } -- cgit 1.3.0-6-gf8a5