From d35bf2f6a1e19ac03b4b808e3a58b1fee9b9ca9c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 5 Jan 2024 22:00:59 -0400 Subject: sugar: showAggregate: translucent: 'single' --- src/util/sugar.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/util') diff --git a/src/util/sugar.js b/src/util/sugar.js index 26982eb6..8ed37ff8 100644 --- a/src/util/sugar.js +++ b/src/util/sugar.js @@ -329,6 +329,9 @@ export function openAggregate({ // generally useful outside of developer debugging purposes - it will be // skipped by default when using showAggregate, showing contained errors // inline with other children of this aggregate's parent. + // + // If set to 'single', it'll be hidden only if there's a single error in the + // aggregate (so it's not grouping multiple errors together). translucent = false, // Value to return when a provided function throws an error. If this is a @@ -416,7 +419,7 @@ export function openAggregate({ const error = Reflect.construct(errorClass, [errors, message]); if (translucent) { - error[Symbol.for(`hsmusic.aggregate.translucent`)] = true; + error[Symbol.for('hsmusic.aggregate.translucent')] = translucent; } throw error; @@ -647,6 +650,13 @@ export function showAggregate(topError, { return cause; } + if (translucency === 'single') { + if (cause.errors?.length === 1) { + return determineCauseHelper(cause.errors[0]); + } else { + return cause; + } + } return determineCauseHelper(cause.cause); }; @@ -663,6 +673,10 @@ export function showAggregate(topError, { return [error]; } + if (translucency === 'single' && error.errors?.length >= 2) { + return [error]; + } + const errors = []; if (error.cause) { -- cgit 1.3.0-6-gf8a5