Merge pull request #486 from Cysharp/hadashiA/inner-ex

Use innerException for `Task.AsUniTask`
master
hadashiA 2023-09-08 17:17:28 +09:00 committed by GitHub
commit b071eeadfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -0,0 +1,34 @@
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();
});
}
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();