Report UniTask exceptions in console without Forget or await?
oxysoft opened this issue · 6 comments
It seems that we must call Forget()
or await the task in order for exceptions to be reported. "Forget" is a very ironic name, because if you forget to call it you will blow your entire leg off. In fact, it happened to us many times and led to some of the hardest bugs I've had to track down in my entire career!
We've been putting Forget()
all over the place, but are there any other benefits aside from error reporting? Otherwise, I think we should try to figure out a way to print the errors in the Unity console without it.
Cheers! Much love for UniTask
Looks like that should've been fixed in #323.
I'm also having exceptions swallowed by UniTask, but I'm not sure what the cause is. This definitely continues to be an issue.
[Edit] Actually, it looks like #323 was only a half-fix. It reports the exception if it was synchronously thrown, but not if it was asynchronously thrown.
Ah, interesting. So all errors thrown from a task discarded with .Forget()
are lost? I feel like that's not the case.
Errors reported if you await, Forget() it or when task is garbage collected.
Last is hasdly predictable and may never happen.
It is recommended that UniTask be used with await
. In fact, C# compiler report warnings if you do not do so.
Forget()
is there to make it clear that await is to be avoided.
Neither await nor Forget may be used incorrectly. Even in that case, a mechanism is in place to report an error when GC collect.
( As far as I know, System.Task eventually does the same thing.
Tasks that detect an error internally do not report it immediately; they await, or continue to hold it until needed.
https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskExceptionHolder.cs,68 )
So I'm going to Close this issue, but if you have a bug with this behavior in a specific case, please let me know the reproduction code.