aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-08 19:25:29 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-08 19:25:29 +0100
commitd1e16a47819509ed645bb93e1a173e0a97025cef (patch)
treeefbe886d9ac1ab4ea01788cb4842812fd0af9079 /src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
parentf694daf322bbb4ff530a9332547c5c8337c3e0c0 (diff)
downloadLocalTransactionLedger-d1e16a47819509ed645bb93e1a173e0a97025cef.tar.gz
LocalTransactionLedger-d1e16a47819509ed645bb93e1a173e0a97025cef.tar.bz2
LocalTransactionLedger-d1e16a47819509ed645bb93e1a173e0a97025cef.zip
build: Move mod to subproject
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt39
1 files changed, 0 insertions, 39 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt b/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
deleted file mode 100644
index 96b70ec..0000000
--- a/src/main/kotlin/moe/nea/ledger/utils/telemetry/ExceptionContextValue.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package moe.nea.ledger.utils.telemetry
-
-import com.google.gson.JsonArray
-import com.google.gson.JsonElement
-import com.google.gson.JsonObject
-
-class ExceptionContextValue(val exception: Throwable) : ContextValue {
- val stackTrace by lazy {
- exception.stackTraceToString()
- }
-
- override fun serialize(): JsonElement {
- val jsonObject = JsonObject()
- jsonObject.addProperty("exception_stackTrace", stackTrace)
- jsonObject.add("exception_structure", walkExceptions(exception, 6))
- return jsonObject
- }
-
- private fun walkExceptions(exception: Throwable, searchDepth: Int): JsonElement {
- val obj = JsonObject()
- obj.addProperty("class", exception.javaClass.name)
- obj.addProperty("message", exception.message)
- // TODO: allow exceptions to implement an "extra info" interface
- if (searchDepth > 0) {
- val cause = exception.cause
- if (cause != null && cause !== exception) {
- obj.add("cause", walkExceptions(cause, searchDepth - 1))
- }
- val suppressions = JsonArray()
- for (suppressedException in exception.suppressedExceptions) {
- suppressions.add(walkExceptions(suppressedException, searchDepth - 1))
- }
- if (suppressions.size() > 0) {
- obj.add("suppressions", suppressions)
- }
- }
- return obj
- }
-}