@@ -44,6 +44,7 @@ import io.homeassistant.companion.android.common.data.websocket.impl.entities.St
4444import io.homeassistant.companion.android.common.data.websocket.impl.entities.TemplateUpdatedEvent
4545import io.homeassistant.companion.android.common.data.websocket.impl.entities.TriggerEvent
4646import io.homeassistant.companion.android.common.data.websocket.impl.entities.UnknownTypeSocketResponse
47+ import io.homeassistant.companion.android.common.util.FailFast
4748import io.homeassistant.companion.android.common.util.MapAnySerializer
4849import io.homeassistant.companion.android.common.util.kotlinJsonMapper
4950import java.io.IOException
@@ -56,6 +57,7 @@ import kotlinx.coroutines.CompletableDeferred
5657import kotlinx.coroutines.CoroutineExceptionHandler
5758import kotlinx.coroutines.CoroutineScope
5859import kotlinx.coroutines.CoroutineStart
60+ import kotlinx.coroutines.DelicateCoroutinesApi
5961import kotlinx.coroutines.Dispatchers
6062import kotlinx.coroutines.Job
6163import kotlinx.coroutines.channels.Channel
@@ -326,6 +328,7 @@ internal class WebSocketCoreImpl(
326328 Timber .d(" Websocket: onOpen" )
327329 }
328330
331+ @OptIn(DelicateCoroutinesApi ::class )
329332 override fun onMessage (webSocket : WebSocket , text : String ) {
330333 Timber .d(" Websocket: onMessage (${if (BuildConfig .DEBUG ) " text: $text " else " text" } )" )
331334 val jsonElement = kotlinJsonMapper.decodeFromString<JsonElement >(text)
@@ -338,7 +341,7 @@ internal class WebSocketCoreImpl(
338341 // Send messages to the queue to ensure they are handled in order and don't block the function
339342 messages.forEach { message ->
340343 Timber .d(" Message id ${message.maybeId()} received" )
341- val success = messageQueue.trySend(
344+ val result = messageQueue.trySend(
342345 wsScope.launch(start = CoroutineStart .LAZY ) {
343346 when (message) {
344347 is AuthRequiredSocketResponse -> Timber .d(" Auth Requested" )
@@ -349,7 +352,14 @@ internal class WebSocketCoreImpl(
349352 }
350353 },
351354 )
352- if (! success.isSuccess) Timber .w(" Message id ${message.maybeId()} not being processed" )
355+
356+ FailFast .failWhen(! result.isSuccess) {
357+ " Failed to process message (ID: ${message.maybeId()} ). " +
358+ " IsFailure? ${result.isFailure} . " +
359+ " Is wsScope active? ${wsScope.isActive} . " +
360+ " Queue status: isClosedForSend = ${messageQueue.isClosedForSend} . " +
361+ " Exception: ${result.exceptionOrNull()} "
362+ }
353363 }
354364 }
355365
0 commit comments