From 578d1a9d48cd029e440ff7a5e4a9a62e28476635 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 16 Apr 2023 10:30:23 +0100 Subject: [PATCH] [core] CoroutineOnDemandValueScope: fix exception message when emit/receive while producer is already finished --- .../src/commonMain/kotlin/network/auth/ProducerState.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/auth/ProducerState.kt b/mirai-core/src/commonMain/kotlin/network/auth/ProducerState.kt index 805304382..1681f2af2 100644 --- a/mirai-core/src/commonMain/kotlin/network/auth/ProducerState.kt +++ b/mirai-core/src/commonMain/kotlin/network/auth/ProducerState.kt @@ -154,16 +154,21 @@ internal sealed interface ProducerState { fun createAlreadyFinishedException(cause: Throwable?): IllegalProducerStateException { val exception = exception + val causeMessage = if (cause == null) { + "" + } else { + ", but attempting to finish with the cause $cause" + } return if (exception == null) { IllegalProducerStateException( this, - "Producer has already finished normally, but attempting to finish with the cause $cause. Previous state was: $previousState", + "Producer has already finished normally$causeMessage. Previous state was: $previousState", cause = cause ) } else { IllegalProducerStateException( this, - "Producer has already finished with the suppressed exception, but attempting to finish with the cause $cause. Previous state was: $previousState", + "Producer has already finished with the suppressed exception$causeMessage. Previous state was: $previousState", cause = cause ).apply { addSuppressed(exception)