Skip to content

Commit c8c6e84

Browse files
committed
Replace try catch
1 parent 36c4dc9 commit c8c6e84

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

app/src/main/java/to/bitkit/services/MigrationService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,12 @@ class MigrationService @Inject constructor(
10351035
suspend fun restoreFromRNRemoteBackup() {
10361036
setRestoringFromRNRemoteBackup(true)
10371037

1038-
try {
1038+
runCatching {
10391039
fetchRNRemoteLdkData()
10401040
val bitkitFiles = rnBackupClient.listFiles(fileGroup = "bitkit")?.list ?: emptyList()
10411041
retrieveAndApplyBitkitBackups(bitkitFiles)
10421042
markMigrationCompleted()
1043-
} catch (e: Exception) {
1043+
}.onFailure { e ->
10441044
Logger.error("RN remote backup restore failed", e, context = TAG)
10451045
throw e
10461046
}

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class AppViewModel @Inject constructor(
390390
if (isCompletingMigration) return
391391
isCompletingMigration = true
392392

393-
try {
393+
runCatching {
394394
lightningRepo.getPayments().onSuccess { payments ->
395395
activityRepo.syncLdkNodePayments(payments)
396396
}.onFailure { e ->
@@ -406,10 +406,10 @@ class AppViewModel @Inject constructor(
406406
Logger.warn("Sync failed during migration: $e", e, context = TAG)
407407
finishMigrationWithFallbackSync()
408408
}
409-
} catch (e: Exception) {
409+
}.onFailure { e ->
410410
Logger.error("Migration completion error: $e", e, context = TAG)
411411
finishMigrationWithError()
412-
} finally {
412+
}.also {
413413
isCompletingMigration = false
414414
}
415415
}

app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class WalletViewModel @Inject constructor(
116116

117117
migrationService.setShowingMigrationLoading(true)
118118

119-
try {
119+
runCatching {
120120
migrationService.migrateFromReactNative()
121121
walletRepo.setWalletExistsState()
122122
walletExists = walletRepo.walletExists()
@@ -127,7 +127,7 @@ class WalletViewModel @Inject constructor(
127127
} else {
128128
migrationService.setShowingMigrationLoading(false)
129129
}
130-
} catch (e: Exception) {
130+
}.onFailure { e ->
131131
Logger.error("RN migration failed: $e", e, context = "WalletViewModel")
132132
migrationService.markMigrationChecked()
133133
migrationService.setShowingMigrationLoading(false)
@@ -183,13 +183,12 @@ class WalletViewModel @Inject constructor(
183183

184184
private suspend fun restoreFromBackup() {
185185
_restoreState.update { RestoreState.InProgress.Metadata }
186-
try {
186+
runCatching {
187187
restoreFromMostRecentBackup()
188-
} catch (e: Exception) {
188+
}.onFailure { e ->
189189
Logger.error("Restore from backup failed", e, context = TAG)
190-
} finally {
191-
_restoreState.update { RestoreState.Completed }
192190
}
191+
_restoreState.update { RestoreState.Completed }
193192
}
194193

195194
private suspend fun restoreFromMostRecentBackup() {

0 commit comments

Comments
 (0)