Remove try/catch block

We don't expect any of the code that was previously inside the `try` block to throw.
This commit is contained in:
cketti 2023-12-19 20:24:38 +01:00
parent cba9ca31aa
commit 6fb4bfae00
3 changed files with 13 additions and 28 deletions

View file

@ -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
}
}

View file

@ -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)

View file

@ -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)