Use innerException for Task.AsUniTask

master
hadashiA 2023-09-01 10:37:46 +09:00
parent 4c3d6938ed
commit 8eac07ad24
2 changed files with 42 additions and 2 deletions

View File

@ -0,0 +1,40 @@
using System;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Xunit;
namespace NetCoreTests
{
public class TaskExtensionsTest
{
[Fact]
public async Task PropagateException()
{
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await ThrowAsync().AsUniTask();
});
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await ThrowOrValueAsync().AsUniTask();
});
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await Task.WhenAll(ThrowAsync(), ThrowAsync(), ThrowAsync());
});
}
async Task ThrowAsync()
{
throw new InvalidOperationException();
}
async Task<int> ThrowOrValueAsync()
{
throw new InvalidOperationException();
}
}
}

View File

@ -28,7 +28,7 @@ namespace Cysharp.Threading.Tasks
p.TrySetCanceled(); p.TrySetCanceled();
break; break;
case TaskStatus.Faulted: case TaskStatus.Faulted:
p.TrySetException(x.Exception); p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
break; break;
case TaskStatus.RanToCompletion: case TaskStatus.RanToCompletion:
p.TrySetResult(x.Result); p.TrySetResult(x.Result);
@ -58,7 +58,7 @@ namespace Cysharp.Threading.Tasks
p.TrySetCanceled(); p.TrySetCanceled();
break; break;
case TaskStatus.Faulted: case TaskStatus.Faulted:
p.TrySetException(x.Exception); p.TrySetException(x.Exception.InnerExceptions.Count == 1 ? x.Exception.InnerException : x.Exception);
break; break;
case TaskStatus.RanToCompletion: case TaskStatus.RanToCompletion:
p.TrySetResult(); p.TrySetResult();