diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-05 22:00:59 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-06 12:50:30 -0400 |
commit | d35bf2f6a1e19ac03b4b808e3a58b1fee9b9ca9c (patch) | |
tree | 31dd53a968ede26ab51cb26fc991e96bcf07449a /src/util | |
parent | b5386dea10c122ac1a71d82a77014cf37f8c11db (diff) |
sugar: showAggregate: translucent: 'single'
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/sugar.js | 16 |
1 files changed, 15 insertions, 1 deletions
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) { |