From 6fb4f2d6d257ae33fcf21fc5d9e8f8af438ebc5f Mon Sep 17 00:00:00 2001 From: hadashiA Date: Fri, 1 Sep 2023 16:58:11 +0900 Subject: [PATCH] Support exception unwrapping for AsUniTask of Task.WhenAll --- src/UniTask.NetCoreTests/TaskExtensionsTest.cs | 9 ++++++--- .../Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/UniTask.NetCoreTests/TaskExtensionsTest.cs b/src/UniTask.NetCoreTests/TaskExtensionsTest.cs index 845a062..62f7666 100644 --- a/src/UniTask.NetCoreTests/TaskExtensionsTest.cs +++ b/src/UniTask.NetCoreTests/TaskExtensionsTest.cs @@ -19,14 +19,17 @@ namespace NetCoreTests { await ThrowOrValueAsync().AsUniTask(); }); - + } + [Fact] + public async Task PropagateWhenAllException() + { await Assert.ThrowsAsync(async () => { - await Task.WhenAll(ThrowAsync(), ThrowAsync(), ThrowAsync()); + await Task.WhenAll(ThrowAsync(), ThrowAsync(), ThrowAsync()).AsUniTask(); }); } - + async Task ThrowAsync() { throw new InvalidOperationException(); diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs index 77ce536..6407be5 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs @@ -28,7 +28,7 @@ namespace Cysharp.Threading.Tasks p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception); + p.TrySetException(x.Exception.InnerException); break; case TaskStatus.RanToCompletion: p.TrySetResult(x.Result); @@ -58,7 +58,7 @@ namespace Cysharp.Threading.Tasks p.TrySetCanceled(); break; case TaskStatus.Faulted: - p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception); + p.TrySetException(x.Exception.InnerException); break; case TaskStatus.RanToCompletion: p.TrySetResult();