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

support retrying, if multiple exception are thrown #116

Merged
merged 6 commits into from
May 6, 2023

Conversation

mitohato14
Copy link
Contributor

@mitohato14 mitohato14 commented May 6, 2023

The following issue: #96.

Originally crashed when multiple exceptions occurred, but changed to allow multiple retries.
Defined as an extension function at the same time.

I also thought about allowing another process to be performed instead of retrying when an exception occurs, but I decided that there would be more cases of retries, so I made the process assuming a retry.

Screen_recording_20230506_164743.mp4

@mitohato14 mitohato14 requested a review from a team May 6, 2023 07:19
@mitohato14 mitohato14 self-assigned this May 6, 2023
fun <T> Flow<T>.handleErrorAndRetry(
actionLabel: String,
userMessageStateHolder: UserMessageStateHolder,
retryAction: ((Throwable) -> Unit)? = null,
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a suspend lambda? This is because we might call repository.refresh(). 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course.
Suspend lambda can also be executed as a retry process.
c4f582e

userMessageStateHolder: UserMessageStateHolder,
retryAction: ((Throwable) -> Unit)? = null,
) {
retry { throwable ->
Copy link
Member

Choose a reason for hiding this comment

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

👍

@github-actions
Copy link

github-actions bot commented May 6, 2023

Test Results

3 files  ±0  3 suites  ±0   18s ⏱️ +6s
2 tests ±0  2 ✔️ ±0  0 💤 ±0  0 ±0 
3 runs  ±0  3 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 845c126. ± Comparison against base commit 3029092.

♻️ This comment has been updated with latest results.

@takahirom
Copy link
Member

takahirom commented May 6, 2023

This is just my preference, but how about separating the method like this? 👀
https://github.com/DroidKaigi/conference-app-2023/pull/117/files
This is because if you pass the action parameter, the "retry" may not be used, which could cause bugs during maintenance.

@@ -196,6 +186,30 @@ fun <T1, T2, T3, T4, R> ViewModel.buildUiState(
)
)

fun <T> Flow<T>.handleErrorAndRetry(
actionLabel: String,
userMessageStateHolder: UserMessageStateHolder,
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking of using a context receiver to pass UserMessageStateHolder. like context(UserMessageStateHolder). But we can change it after merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.
Since the codebase is not yet ready, let's do it after the merge. 👍

Copy link
Member

@takahirom takahirom left a comment

Choose a reason for hiding this comment

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

I have a little suggestion, But It looks great! Thanks!

@mitohato14
Copy link
Contributor Author

This is just my preference, but how about separating the method like this? 👀 https://github.com/DroidKaigi/conference-app-2023/pull/117/files This is because if you pass the action parameter, the "retry" may not be used, which could cause bugs during maintenance.

It looks good.:+1:
By separating them, it looks like the retry operator will be used only when necessary, which will help control bugs.

…rrorAndRetry-into-handleErrorAndRetry-and-handleErrorAndRetryAction/2023-05-06
…rAndRetry-into-handleErrorAndRetry-and-handleErrorAndRetryAction/2023-05-06

Separate handleErrorAndRetry into handleErrorAndRetry and handleErrorAndRetryAction
@github-actions
Copy link

github-actions bot commented May 6, 2023

Hi @mitohato14! Codes seem to be unformatted. Please run ./gradlew spotlessKotlinApply to fix this issue. Thank you for your contribution.

@mitohato14
Copy link
Contributor Author

@takahirom
Thanks for the suggestion.
I have merged them into this PR.
https://github.com/DroidKaigi/conference-app-2023/pull/117/files

@mitohato14 mitohato14 merged commit 6bcf82f into main May 6, 2023
4 checks passed
@mitohato14 mitohato14 deleted the handle-error-and-retry branch May 6, 2023 08:59
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.

None yet

2 participants