Skip to content

Commit

Permalink
fix(common): config deserializer error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Dec 4, 2023
1 parent d762040 commit ce2fe64
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.rhunk.snapenhance.common.config

import android.content.Context
import com.google.gson.JsonObject
import me.rhunk.snapenhance.common.logger.AbstractLogger
import kotlin.reflect.KProperty

typealias ConfigParamsBuilder = ConfigParams.() -> Unit
Expand Down Expand Up @@ -78,9 +79,12 @@ open class ConfigContainer(

fun fromJson(json: JsonObject) {
properties.forEach { (key, _) ->
val jsonElement = json.get(key.name) ?: return@forEach
//TODO: check incoming values
properties[key]?.setAny(key.dataType.deserializeAny(jsonElement))
runCatching {
val jsonElement = json.get(key.name) ?: return@forEach
properties[key]?.setAny(key.dataType.deserializeAny(jsonElement))
}.onFailure {
AbstractLogger.directError("Failed to deserialize property ${key.name}", it)
}
}
}

Expand Down

0 comments on commit ce2fe64

Please sign in to comment.