Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use always innerException for Task.AsUniTask #500

Merged
merged 2 commits into from
Sep 14, 2023
Merged

Conversation

hadashiA
Copy link
Contributor

@hadashiA hadashiA commented Sep 8, 2023

refs: #422

After #486, There was some further discussion.

UniTask is a world line like Task when there is only await, so it may be possible to throw away other exceptions to match the behavior of await Task...

So, if await Task.WhenAll(...).AsUniTask() throws an exception, always use inner exception just like await Task.WhenAll(...).

@hadashiA
Copy link
Contributor Author

@neuecc I added handling of cases where InnerExceptions is empty.. !

@neuecc
Copy link
Member

neuecc commented Sep 14, 2023

good!

@hadashiA hadashiA merged commit 90c5e5a into master Sep 14, 2023
4 checks passed
@hadashiA hadashiA deleted the hadashiA/inner-ex2 branch September 14, 2023 07:22
@krisrok
Copy link

krisrok commented Sep 14, 2023

Good to see this resolved but I don't get why my previous PR #428 was closed as this basically did the same thing. Except my solution also accounts for nested AggregateExceptions which yours does currently not.

@hadashiA please have look here:
krisrok/UniTask@62a2a2e...krisrok:UniTask:feature/asunitask-always-unwrap-aggregateexception-before-tests

@hadashiA
Copy link
Contributor Author

@krisrok

Good to see this resolved but I don't get why my previous PR #428 was closed as this basically did the same thing.

My understanding is that the decision was made because the behavior of handling only the first one of InnerExceptions comes only from the Task world, and they did not want to bring that into UniTask in general.

Except my solution also accounts for nested AggregateExceptions which yours does currently not.

I see. Perhaps your implementation could be superior. I will check. Thanks.

@krisrok
Copy link

krisrok commented Sep 15, 2023

My understanding is that the decision was made because the behavior of handling only the first one of InnerExceptions comes only from the Task world, and they did not want to bring that into UniTask in general.

You're right, and this is no easy decision as we can read on similar discussions on the .NET repos. I personally would just want UniTask to be as close to the expectations of a "normal" .NET user who already knows Task and its behaviours. This is of course just my sole opinion.

I'll quote myself from here:

To reproduce .NET's behaviour, UniTask would have to always return the AggregateException's first exception regardless if there is more.

But this poses a problem because in UniTask's implementation you cannot access e.g. UniTask.Exception afterwards, you only ever get the thrown exception.

Task on the other hand has the Exception property which still holds the AggregateException even though it never throws an aggregate, only the first Exception. You'd have to actively look at Task.Exception to know if there's more.

If you want some tests regarding UniTask-Task-parity in regards of exceptions you can have a look at this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants