aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt b/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
index 344c8bc..e0c83f9 100644
--- a/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
+++ b/src/main/kotlin/moe/nea/ledger/utils/ErrorUtil.kt
@@ -4,6 +4,7 @@ import moe.nea.ledger.utils.di.Inject
import moe.nea.ledger.utils.telemetry.ContextValue
import moe.nea.ledger.utils.telemetry.EventRecorder
import moe.nea.ledger.utils.telemetry.Span
+import java.util.concurrent.CompletableFuture
class ErrorUtil {
@@ -27,6 +28,14 @@ class ErrorUtil {
return getOrNull()
}
+ fun <T : CompletableFuture<*>> listenToFuture(t: T): T {
+ t.handle { ignored, exception ->
+ if (exception != null)
+ report(exception, "Uncaught exception in completable future")
+ }
+ return t
+ }
+
inline fun <T> catch(
vararg pairs: Pair<String, ContextValue>,
crossinline function: () -> T