From 8ed6dad23ced91c858c276e49ab2a7da3754c8bb Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Sep 2020 04:16:31 +0530 Subject: OnboardingActivity: use runCatching to replace exception handling Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt b/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt index ed05ed0d..d26860dc 100644 --- a/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt @@ -13,6 +13,8 @@ import androidx.activity.result.contract.ActivityResultContracts.StartActivityFo import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import com.github.ajalt.timberkt.d +import com.github.michaelbull.result.onFailure +import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.zeapo.pwdstore.databinding.ActivityOnboardingBinding import com.zeapo.pwdstore.git.BaseGitActivity @@ -174,7 +176,7 @@ class OnboardingActivity : AppCompatActivity() { private fun createRepository() { val localDir = PasswordRepository.getRepositoryDirectory() - try { + runCatching { check(localDir.exists() || localDir.mkdir()) { "Failed to create directory!" } PasswordRepository.createRepository(localDir) if (!PasswordRepository.isInitialized) { @@ -185,7 +187,7 @@ class OnboardingActivity : AppCompatActivity() { } else { throw IllegalStateException("Failed to initialize repository state.") } - } catch (e: Exception) { + }.onFailure { e -> e.printStackTrace() if (!localDir.delete()) { d { "Failed to delete local repository: $localDir" } -- cgit v1.2.3