diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 20:27:20 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 22:49:05 +0530 |
commit | 5951a983b10f8c2364c93230f2a3affef46851a8 (patch) | |
tree | bee4a378cf688a81d8e47be98f88e716857e9182 /app | |
parent | 361a801e47f188d028eeecfc72344eb27d631492 (diff) |
GitConfigActivity: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt index c6ab3ca3..46a54f57 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitConfigActivity.kt @@ -12,6 +12,9 @@ import androidx.core.os.postDelayed import androidx.lifecycle.lifecycleScope import com.github.ajalt.timberkt.e import com.github.michaelbull.result.fold +import com.github.michaelbull.result.getOrElse +import com.github.michaelbull.result.onFailure +import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.R @@ -69,10 +72,9 @@ class GitConfigActivity : BaseGitActivity() { binding.gitAbortRebase.alpha = if (isRebasing) 1.0f else 0.5f } binding.gitLog.setOnClickListener { - try { - intent = Intent(this, GitLogActivity::class.java) - startActivity(intent) - } catch (ex: Exception) { + runCatching { + startActivity(Intent(this, GitLogActivity::class.java)) + }.onFailure { ex -> e(ex) { "Failed to start GitLogActivity" } } } @@ -112,7 +114,7 @@ class GitConfigActivity : BaseGitActivity() { * The state is recognized to be either pointing to a branch or detached. */ private fun headStatusMsg(repo: Repository): String { - return try { + return runCatching { val headRef = repo.getRef(Constants.HEAD) if (headRef.isSymbolic) { val branchName = headRef.target.name @@ -122,7 +124,7 @@ class GitConfigActivity : BaseGitActivity() { val commitHash = headRef.objectId.abbreviate(8).name() getString(R.string.git_head_detached, commitHash) } - } catch (ex: Exception) { + }.getOrElse { ex -> e(ex) { "Error getting HEAD reference" } getString(R.string.git_head_missing) } |