Skip to content

Commit

Permalink
Log class name on cast failure when storing files in object store (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel-figure authored Jan 16, 2024
1 parent c3f6193 commit 174f066
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.eos.store.StoreProtoResponse
import io.provenance.api.models.p8e.PermissionInfo
import io.provenance.api.util.awaitAllBytes
import io.provenance.api.util.buildLogMessage
import io.provenance.entity.KeyType
import io.provenance.scope.util.toUuid
import kotlinx.coroutines.reactor.awaitSingle
Expand Down Expand Up @@ -85,7 +86,12 @@ class StoreFile(

private inline fun <reified T> Map<String, Part>.getAsType(key: String): T =
T::class.java.cast(get(key))
?: throw IllegalArgumentException("Failed to retrieve and cast provided argument.")
?: throw IllegalArgumentException(
buildLogMessage(
"Failed to retrieve and cast provided argument",
"javaClass" to T::class.java.name,
)
)

data class Args(
val account: AccountInfo?,
Expand Down
11 changes: 11 additions & 0 deletions service/src/main/kotlin/io/provenance/api/util/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ private val debugObjectMapper by lazy {
}

fun Any.toPrettyJson(): String = debugObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this)

fun buildLogMessage(message: String, args: List<Pair<String, Any?>>): String =
args.joinToString(
separator = ", ",
prefix = "[",
postfix = "]"
) { "${it.first}=${it.second}" }.let { argString ->
"$message $argString".trim()
}

fun buildLogMessage(message: String, vararg args: Pair<String, Any?>): String = buildLogMessage(message, args.toList())

0 comments on commit 174f066

Please sign in to comment.