Skip to content

Commit 174f066

Browse files
Log class name on cast failure when storing files in object store (#137)
1 parent c3f6193 commit 174f066

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

service/src/main/kotlin/io/provenance/api/domain/usecase/objectStore/store/StoreFile.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.provenance.api.models.account.AccountInfo
1010
import io.provenance.api.models.eos.store.StoreProtoResponse
1111
import io.provenance.api.models.p8e.PermissionInfo
1212
import io.provenance.api.util.awaitAllBytes
13+
import io.provenance.api.util.buildLogMessage
1314
import io.provenance.entity.KeyType
1415
import io.provenance.scope.util.toUuid
1516
import kotlinx.coroutines.reactor.awaitSingle
@@ -85,7 +86,12 @@ class StoreFile(
8586

8687
private inline fun <reified T> Map<String, Part>.getAsType(key: String): T =
8788
T::class.java.cast(get(key))
88-
?: throw IllegalArgumentException("Failed to retrieve and cast provided argument.")
89+
?: throw IllegalArgumentException(
90+
buildLogMessage(
91+
"Failed to retrieve and cast provided argument",
92+
"javaClass" to T::class.java.name,
93+
)
94+
)
8995

9096
data class Args(
9197
val account: AccountInfo?,

service/src/main/kotlin/io/provenance/api/util/Debug.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ private val debugObjectMapper by lazy {
1111
}
1212

1313
fun Any.toPrettyJson(): String = debugObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(this)
14+
15+
fun buildLogMessage(message: String, args: List<Pair<String, Any?>>): String =
16+
args.joinToString(
17+
separator = ", ",
18+
prefix = "[",
19+
postfix = "]"
20+
) { "${it.first}=${it.second}" }.let { argString ->
21+
"$message $argString".trim()
22+
}
23+
24+
fun buildLogMessage(message: String, vararg args: Pair<String, Any?>): String = buildLogMessage(message, args.toList())

0 commit comments

Comments
 (0)