From 2041ec3f19318777c456ae6e2075f0aff74c45a7 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 5 Sep 2020 05:48:27 +0530 Subject: Extensions: use runCatching to replace exception handling Signed-off-by: Harsh Shandilya --- app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt index ab78e98f..d54e26cd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/Extensions.kt @@ -27,6 +27,8 @@ import androidx.security.crypto.MasterKey import com.github.ajalt.timberkt.d import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Result +import com.github.michaelbull.result.getOrElse +import com.github.michaelbull.result.runCatching import com.google.android.material.snackbar.Snackbar import com.zeapo.pwdstore.R import com.zeapo.pwdstore.git.operation.GitOperation @@ -77,9 +79,9 @@ fun File.contains(other: File): Boolean { return false if (!other.exists()) return false - val relativePath = try { + val relativePath = runCatching { other.relativeTo(this) - } catch (e: Exception) { + }.getOrElse { return false } // Direct containment is equivalent to the relative path being equal to the filename. -- cgit v1.2.3