From 6fb4bfae005bcc8c103276e4df4b86bd2f389390 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 19 Dec 2023 20:24:38 +0100 Subject: [PATCH] Remove try/catch block We don't expect any of the code that was previously inside the `try` block to throw. --- .../specialfolders/SpecialFoldersContract.kt | 2 - .../specialfolders/SpecialFoldersViewModel.kt | 37 ++++++------------- .../SpecialFoldersViewModelTest.kt | 2 +- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersContract.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersContract.kt index 8836f6121..01211831e 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersContract.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersContract.kt @@ -58,8 +58,6 @@ interface SpecialFoldersContract { sealed interface Failure { val message: String - data class MissingIncomingServerSettings(override val message: String) : Failure data class LoadFoldersFailed(override val message: String) : Failure - data class SaveFailed(override val message: String) : Failure } } diff --git a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModel.kt b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModel.kt index 8aa752fc7..32710c763 100644 --- a/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModel.kt +++ b/feature/account/setup/src/main/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModel.kt @@ -9,7 +9,6 @@ import app.k9mail.feature.account.common.domain.entity.SpecialFolderSettings import app.k9mail.feature.account.setup.domain.DomainContract.UseCase import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Effect import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Event -import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.Failure.SaveFailed import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.FormEvent import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.State import app.k9mail.feature.account.setup.ui.specialfolders.SpecialFoldersContract.ViewModel @@ -100,34 +99,22 @@ class SpecialFoldersViewModel( } } - @Suppress("TooGenericExceptionCaught") private suspend fun saveSpecialFolderSettings() { val formState = state.value.formState - try { - accountStateRepository.setSpecialFolderSettings( - SpecialFolderSettings( - archiveSpecialFolderOption = formState.selectedArchiveSpecialFolderOption, - draftsSpecialFolderOption = formState.selectedDraftsSpecialFolderOption, - sentSpecialFolderOption = formState.selectedSentSpecialFolderOption, - spamSpecialFolderOption = formState.selectedSpamSpecialFolderOption, - trashSpecialFolderOption = formState.selectedTrashSpecialFolderOption, - ), + accountStateRepository.setSpecialFolderSettings( + SpecialFolderSettings( + archiveSpecialFolderOption = formState.selectedArchiveSpecialFolderOption, + draftsSpecialFolderOption = formState.selectedDraftsSpecialFolderOption, + sentSpecialFolderOption = formState.selectedSentSpecialFolderOption, + spamSpecialFolderOption = formState.selectedSpamSpecialFolderOption, + trashSpecialFolderOption = formState.selectedTrashSpecialFolderOption, + ), + ) + updateState { state -> + state.copy( + isLoading = false, ) - updateState { state -> - state.copy( - isLoading = false, - ) - } - } catch (exception: Exception) { - Timber.e(exception, "Error while saving special folders") - updateState { state -> - state.copy( - isLoading = false, - error = SaveFailed(exception.message ?: "unknown error"), - ) - } - return } delay(CONTINUE_NEXT_DELAY) diff --git a/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModelTest.kt b/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModelTest.kt index 705de8289..601ba1839 100644 --- a/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModelTest.kt +++ b/feature/account/setup/src/test/kotlin/app/k9mail/feature/account/setup/ui/specialfolders/SpecialFoldersViewModelTest.kt @@ -245,7 +245,7 @@ class SpecialFoldersViewModelTest { @Test fun `should show form when OnRetryClicked event received`() = runTest { - val initialState = State(error = SpecialFoldersContract.Failure.SaveFailed("error")) + val initialState = State(error = SpecialFoldersContract.Failure.LoadFoldersFailed("irrelevant")) val testSubject = createTestSubject(initialState = initialState) val turbines = turbinesWithInitialStateCheck(testSubject, initialState)