From 65922863b627159253797a140184747a95307a46 Mon Sep 17 00:00:00 2001 From: krisrok <3404365+krisrok@users.noreply.github.com> Date: Tue, 20 Dec 2022 14:23:07 +0100 Subject: [PATCH] Account for nested aggregates by flattening --- .../Plugins/UniTask/Runtime/UniTaskCompletionSource.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs index 81afa51..4f09a1c 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs @@ -46,12 +46,13 @@ namespace Cysharp.Threading.Tasks public ExceptionHolder(Exception exception) { - if (exception is AggregateException aex && aex.InnerExceptions?.Count == 1) + var flattenedAggregate = (exception as AggregateException)?.Flatten(); + if (flattenedAggregate?.InnerExceptions?.Count == 1) { - this.exception = ExceptionDispatchInfo.Capture(aex.InnerExceptions[0]); + this.exception = ExceptionDispatchInfo.Capture(flattenedAggregate.InnerExceptions[0]); } else - { + { this.exception = ExceptionDispatchInfo.Capture(exception); } }