File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
common/src/main/kotlin/com/lambda/config Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1818package com.lambda.config
1919
2020import com.google.gson.JsonElement
21+ import com.lambda.Lambda.LOG
2122import com.lambda.Lambda.gson
2223import com.lambda.context.SafeContext
2324import com.lambda.threading.runSafe
@@ -97,7 +98,12 @@ abstract class AbstractSetting<T : Any>(
9798 gson.toJsonTree(value, type)
9899
99100 override fun loadFromJson (serialized : JsonElement ) {
100- value = gson.fromJson(serialized, type)
101+ runCatching {
102+ value = gson.fromJson(serialized, type)
103+ }.onFailure {
104+ LOG .warn(" Failed to load setting ${this .name} with value $serialized . Resetting to default value $defaultValue " , it)
105+ value = defaultValue
106+ }
101107 }
102108
103109 /* *
Original file line number Diff line number Diff line change @@ -78,9 +78,7 @@ abstract class Configurable(
7878
7979 override fun loadFromJson (serialized : JsonElement ) {
8080 serialized.asJsonObject.entrySet().forEach { (name, value) ->
81- settings.find {
82- it.name == name
83- }?.loadFromJson(value)
81+ settings.find { it.name == name }?.loadFromJson(value)
8482 ? : LOG .warn(" No saved setting found for $name with $value in ${this ::class .simpleName} " )
8583 }
8684 }
You can’t perform that action at this time.
0 commit comments