diff --git a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Models/RunAnywhereModelLifecycle.kt b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Models/RunAnywhereModelLifecycle.kt index 7ec5259bbf..6b1adccc60 100644 --- a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Models/RunAnywhereModelLifecycle.kt +++ b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Models/RunAnywhereModelLifecycle.kt @@ -24,6 +24,7 @@ import com.runanywhere.sdk.public.RunAnywhere import com.runanywhere.sdk.public.types.RAModelInfo import com.runanywhere.sdk.public.types.RAModelLoadRequest import com.runanywhere.sdk.public.types.RAModelLoadResult +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -48,7 +49,9 @@ suspend fun RunAnywhere.loadModel(request: RAModelLoadRequest): RAModelLoadResul } try { ensureServicesReady() - } catch (_: Throwable) { + } catch (e: CancellationException) { + throw e + } catch (_: Exception) { } val result = CppBridgeModelLifecycle.load(request) diff --git a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/STT/RunAnywhereSTT.kt b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/STT/RunAnywhereSTT.kt index e587c58529..952d2db139 100644 --- a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/STT/RunAnywhereSTT.kt +++ b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/STT/RunAnywhereSTT.kt @@ -20,6 +20,7 @@ import com.runanywhere.sdk.infrastructure.logging.SDKLogger import com.runanywhere.sdk.public.RunAnywhere import com.runanywhere.sdk.public.types.RASTTOptions import com.runanywhere.sdk.public.types.RASTTOutput +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow @@ -108,7 +109,9 @@ fun RunAnywhere.transcribeStream( trySend(RASTTPartialResult(is_final = true)) } close() - } catch (e: Throwable) { + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { trySend( RASTTPartialResult( text = "STT stream failed: ${e.message ?: e::class.simpleName.orEmpty()}", diff --git a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Storage/RunAnywhereDownload.kt b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Storage/RunAnywhereDownload.kt index 1723064217..1db29c34aa 100644 --- a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Storage/RunAnywhereDownload.kt +++ b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/Storage/RunAnywhereDownload.kt @@ -146,7 +146,7 @@ suspend fun RunAnywhere.downloadModel( downloadLogger.info( "Download cancelled for ${resolvedModel.id} (task=${startResult.task_id})", ) - } catch (e: Throwable) { + } catch (e: Exception) { downloadLogger.warn( "Failed to cancel native download for ${resolvedModel.id} " + "(task=${startResult.task_id}): ${e.message}", diff --git a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt index 99d66a4d70..b689e6c11b 100644 --- a/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt +++ b/sdk/runanywhere-kotlin/src/main/kotlin/com/runanywhere/sdk/public/extensions/TTS/RunAnywhereTTS.kt @@ -24,6 +24,7 @@ import com.runanywhere.sdk.native.bridge.RunAnywhereBridge import com.runanywhere.sdk.public.RunAnywhere import com.runanywhere.sdk.public.types.RATTSOptions import com.runanywhere.sdk.public.types.RATTSOutput +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.NonCancellable @@ -127,7 +128,9 @@ fun RunAnywhere.synthesizeStream( trySend(output).isSuccess } } - } catch (t: Throwable) { + } catch (t: CancellationException) { + throw t + } catch (t: Exception) { ttsLogger.warn("synthesizeStream errored: ${t.message}") } finally { close()