From 0799ba3e43778d346788d0d5eedb17306bb72601 Mon Sep 17 00:00:00 2001 From: deepseven <5635954+deepseven@users.noreply.github.com> Date: Sun, 22 Mar 2026 09:45:56 +0100 Subject: [PATCH] Fix crash: wrap transcription coroutine in try/catch The fire-and-forget scope.launch(Dispatchers.IO) block that runs transcription has no top-level exception handler. If TranscriptionClient.transcribe() throws an unexpected exception (e.g. malformed URL, SSL error, OOM), it propagates as an uncaught coroutine exception and crashes the entire app process. The crash is particularly bad because the app restarts, syncs again, re-downloads the same file, tries to transcribe again, and crashes in an infinite loop. Fix: wrap the coroutine body in try/catch so transcription errors are logged but never kill the sync service. --- .../main/java/com/middle/app/ble/SyncForegroundService.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/app/src/main/java/com/middle/app/ble/SyncForegroundService.kt b/android/app/src/main/java/com/middle/app/ble/SyncForegroundService.kt index c5ea971..efe2e47 100644 --- a/android/app/src/main/java/com/middle/app/ble/SyncForegroundService.kt +++ b/android/app/src/main/java/com/middle/app/ble/SyncForegroundService.kt @@ -284,6 +284,7 @@ class SyncForegroundService : Service() { skipTranscription = true } else { scope.launch(Dispatchers.IO) { + try { val client = TranscriptionClient(provider, apiKey) val text = client.transcribe(audioFile) if (text != null) { @@ -324,6 +325,10 @@ class SyncForegroundService : Service() { updateNotification(message) skipTranscription = true } + } catch (exception: Exception) { + Log.e(TAG, "Transcription coroutine failed for $filename: $exception") + WebhookLog.error("Transcription error ($filename): ${exception::class.simpleName}: ${exception.message}") + } } } }