From 24da10715fcbcdf0280d7142088313ff085a11d1 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Wed, 27 May 2026 23:41:43 -0400 Subject: [PATCH] Make safeLaunch inherit CoroutineScope's handler --- .../src/main/java/dev/slimevr/util/SafeLaunch.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt b/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt index 9675e9536..e51913285 100644 --- a/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt +++ b/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt @@ -25,10 +25,14 @@ fun CoroutineScope.safeLaunch( start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit, ): Job { - val handler = context[CoroutineExceptionHandler] ?: CoroutineExceptionHandler { ctx, throwable -> - val name = ctx[CoroutineName]?.name ?: "UnknownScope" - AppLogger.coroutines.error(throwable, "Unhandled exception in safeLaunch (scope: $name)") - } + val handler = context[CoroutineExceptionHandler] + ?: this.coroutineContext[CoroutineExceptionHandler] + ?: CoroutineExceptionHandler { ctx, throwable -> + val name = ctx[CoroutineName]?.name ?: "UnknownScope" + AppLogger.coroutines.error( + throwable, "Unhandled exception in safeLaunch (scope: $name)" + ) + } //noinspection RAW_LAUNCH_USAGE return this.launch(context + handler, start = start, block = block) }