summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 04:16:31 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:48:59 +0530
commit8ed6dad23ced91c858c276e49ab2a7da3754c8bb (patch)
treed8621f852f3fe987b5724f00b11aa54f413c4f0a /app/src/main/java
parent2db640d6cb490c5471d5497ffeb6ab68179bebd8 (diff)
OnboardingActivity: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/OnboardingActivity.kt6
1 files 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" }