diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 20:29:55 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-09-05 22:49:34 +0530 |
commit | 83654896b6acc66793f4b279e0a41a0e15b988c4 (patch) | |
tree | 6119d524c3f6099e6beb8f2f1b960ae58af3227d /app/src/main/java | |
parent | 5951a983b10f8c2364c93230f2a3affef46851a8 (diff) |
PasswordRepository: 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/utils/PasswordRepository.kt | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt index fe79a8ea..443e7398 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.kt @@ -9,6 +9,9 @@ import android.content.SharedPreferences import android.os.Build import androidx.annotation.RequiresApi import androidx.core.content.edit +import com.github.michaelbull.result.runCatching +import com.github.michaelbull.result.getOrElse +import com.github.michaelbull.result.onFailure import com.zeapo.pwdstore.Application import java.io.File import java.io.FileFilter @@ -105,14 +108,14 @@ open class PasswordRepository protected constructor() { fun getRepository(localDir: File?): Repository? { if (repository == null && localDir != null) { val builder = FileRepositoryBuilder() - try { - repository = builder.setGitDir(localDir) + repository = runCatching { + builder.setGitDir(localDir) .setFS(Java7FSFactory().detect(null)) .readEnvironment() .build() - } catch (e: Exception) { + }.getOrElse { e -> e.printStackTrace() - return null + null } } return repository @@ -146,7 +149,7 @@ open class PasswordRepository protected constructor() { val remotes = storedConfig.getSubsections("remote") if (!remotes.contains(name)) { - try { + runCatching { val uri = URIish(url) val refSpec = RefSpec("+refs/head/*:refs/remotes/$name/*") @@ -159,11 +162,11 @@ open class PasswordRepository protected constructor() { remoteConfig.update(storedConfig) storedConfig.save() - } catch (e: Exception) { + }.onFailure { e -> e.printStackTrace() } } else if (replace) { - try { + runCatching { val uri = URIish(url) val remoteConfig = RemoteConfig(storedConfig, name) @@ -181,7 +184,7 @@ open class PasswordRepository protected constructor() { remoteConfig.update(storedConfig) storedConfig.save() - } catch (e: Exception) { + }.onFailure { e -> e.printStackTrace() } } |