Skip to content

Commit

Permalink
Merge pull request #500 from Cysharp/hadashiA/inner-ex2
Browse files Browse the repository at this point in the history
Use always innerException for Task.AsUniTask
  • Loading branch information
hadashiA committed Sep 14, 2023
2 parents 8a022ee + 90c8161 commit 90c5e5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/UniTask.NetCoreTests/TaskExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ public async Task PropagateException()
await ThrowOrValueAsync().AsUniTask();
});
}

[Fact]
public async Task PropagateExceptionWhenAll()
{
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await Task.WhenAll(ThrowAsync(), ThrowAsync()).AsUniTask();
});
}

async Task ThrowAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static UniTask<T> AsUniTask<T>(this Task<T> task, bool useCurrentSynchron
p.TrySetCanceled();
break;
case TaskStatus.Faulted:
p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
p.TrySetException(x.Exception.InnerException ?? x.Exception);
break;
case TaskStatus.RanToCompletion:
p.TrySetResult(x.Result);
Expand Down Expand Up @@ -58,7 +58,7 @@ public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationCo
p.TrySetCanceled();
break;
case TaskStatus.Faulted:
p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
p.TrySetException(x.Exception.InnerException ?? x.Exception);
break;
case TaskStatus.RanToCompletion:
p.TrySetResult();
Expand Down

0 comments on commit 90c5e5a

Please sign in to comment.