Skip to content

Commit 9c2cb61

Browse files
committed
Avoid verbose error handling
onFailure already encapsulate the exception so no need to .recoverCatching unlike .recover which rethrows any error
1 parent bd3ec9a commit 9c2cb61

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

common/src/main/kotlin/com/lambda/config/Configuration.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,20 @@ abstract class Configuration : Jsonable {
7979
private fun tryLoad() {
8080
lambdaScope.launch(Dispatchers.IO) {
8181
runCatching { load(primary) }
82-
.onSuccess {
83-
LOG.info("[IO] Config Manager: ${configName.replaceFirstChar(Char::titlecase) }} config loaded.")
84-
}
85-
.onFailure { LOG.error("Failed to load $configName config, loading backup", it) }
86-
.recoverCatching {
82+
.onSuccess { LOG.info("[IO] Config Manager: ${configName.replaceFirstChar(Char::titlecase) }} config loaded.") }
83+
.onFailure {
84+
LOG.error("Failed to load $configName config, loading backup")
8785
runCatching { load(backup) }
8886
.onSuccess { LOG.info("$configName config loaded from backup") }
89-
.onFailure {
90-
LOG.error(
91-
"Failed to load $configName config from backup, unrecoverable error",
92-
it
93-
)
94-
}
87+
.onFailure { LOG.error("Failed to load $configName config from backup, unrecoverable error", it) }
9588
}
9689
}
9790
}
9891

9992
private fun trySave() {
10093
lambdaScope.launch(Dispatchers.IO) {
10194
runCatching { save() }
102-
.onSuccess {
103-
LOG.info("$configName config saved")
104-
}
95+
.onSuccess { LOG.info("$configName config saved") }
10596
.onFailure { LOG.error("Failed to save $configName config", it) }
10697
}
10798
}

0 commit comments

Comments
 (0)