Migrations: use runCatching to replace exception handling

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya
2020-09-05 04:48:45 +05:30
parent c3e6006895
commit 63e2908d36

View File

@@ -11,6 +11,8 @@ import android.content.SharedPreferences
import androidx.core.content.edit import androidx.core.content.edit
import com.github.ajalt.timberkt.e import com.github.ajalt.timberkt.e
import com.github.ajalt.timberkt.i import com.github.ajalt.timberkt.i
import com.github.michaelbull.result.get
import com.github.michaelbull.result.runCatching
import com.zeapo.pwdstore.git.config.GitSettings import com.zeapo.pwdstore.git.config.GitSettings
import com.zeapo.pwdstore.git.config.Protocol import com.zeapo.pwdstore.git.config.Protocol
import com.zeapo.pwdstore.git.sshj.SshKey import com.zeapo.pwdstore.git.sshj.SshKey
@@ -65,14 +67,12 @@ private fun migrateToGitUrlBasedConfig(sharedPrefs: SharedPreferences) {
urlWithFreeEntryScheme.startsWith("http://") -> urlWithFreeEntryScheme.replaceFirst("http", "https") urlWithFreeEntryScheme.startsWith("http://") -> urlWithFreeEntryScheme.replaceFirst("http", "https")
else -> "https://$urlWithFreeEntryScheme" else -> "https://$urlWithFreeEntryScheme"
} }
try { runCatching {
if (URI(url).rawAuthority != null) if (URI(url).rawAuthority != null)
url url
else else
null null
} catch (_: Exception) { }.get()
null
}
} }
} }