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

Better coroutine error handling #54

Merged
merged 7 commits into from
May 11, 2023
Merged

Better coroutine error handling #54

merged 7 commits into from
May 11, 2023

Conversation

fraidev
Copy link
Collaborator

@fraidev fraidev commented Apr 28, 2023

This PR resolves #39

I added class CoroutineUtils.cs that has two methods:

  • Try: Just run a coroutine with an optional handler for the exception (default is just a log).
  • TryWith: Execute the Try method for a specific monoBehaviour.

@fraidev fraidev marked this pull request as ready for review April 28, 2023 21:20
@m-kus m-kus requested a review from k-karuna May 1, 2023 08:53
Copy link
Member

@k-karuna k-karuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this solution is good, but didn't cover all cases. For example, in case of http issues we will receive exception on this line and this exception will be handled by existing CoroutineWrapper class.
So, my suggestion is maybe it will be better to improve CoroutineWrapper class that we can set up errorHandler action on it, and execute it instead of current Completed?.Invoke(default);
And when we wrap with it all coroutines that runs external callbacks and returns through yield return coroutine statement, looks like we will cover all possible exception cases.
Moreover looks like that WrappedRequest method is redundant, we can use ordinary CoroutineWrapper instead.
If you have any thoughts, feel free to write me.

Runtime/Scripts/Helpers/CoroutineUtils.cs Outdated Show resolved Hide resolved
@fraidev
Copy link
Collaborator Author

fraidev commented May 2, 2023

In my opinion this solution is good, but didn't cover all cases. For example, in case of http issues we will receive exception on this line and this exception will be handled by existing CoroutineWrapper class. So, my suggestion is maybe it will be better to improve CoroutineWrapper class that we can set up errorHandler action on it, and execute it instead of current Completed?.Invoke(default); And when we wrap with it all coroutines that runs external callbacks and returns through yield return coroutine statement, looks like we will cover all possible exception cases. Moreover looks like that WrappedRequest method is redundant, we can use ordinary CoroutineWrapper instead. If you have any thoughts, feel free to write me.

I really forgot about the CoroutineWrapper and WrappedRequest usages.
And CoroutineWrapper it was doing a similar job that the new CoroutineUtils.
What do you think to use the CoroutineUtils.Try in the WrappedRequest method and delete CoroutineWrapper because there is no more usage in the codebase?
image

Copy link
Member

@k-karuna k-karuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution did not cover scenarios which are build on several yield return IEnumerator cases. E.g. if we click on Inventory button on UI, we will call this method, that will call GetJson<T> method later, and if we have some network issues, we will get deserealize exception on this line, even if we pass errorHandler on CoroutineUtils.TryWith
So, my previous suggestion was to use something like CoroutineWrappper, that can handle Exceptions inside itself and use them wherever possible.

@k-karuna
Copy link
Member

k-karuna commented May 3, 2023

@fraidev what do you think?

@fraidev
Copy link
Collaborator Author

fraidev commented May 5, 2023

@fraidev what do you think?

Make sense! I reverted the last commits and added one using the CoroutineWrapper with error handling.
Can you check again?

@m-kus
Copy link
Collaborator

m-kus commented May 11, 2023

@fraidev could you please update the changelog?

@k-karuna
Copy link
Member

@m-kus @fraidev I've updated changelog in order not to delay this task.

@k-karuna k-karuna requested review from k-karuna and mismirnov May 11, 2023 14:28
@mismirnov mismirnov merged commit 90c2826 into main May 11, 2023
@mismirnov mismirnov deleted the coroutine-error-handling branch May 11, 2023 14:29
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.

Better coroutine error handling
4 participants