Prechádzať zdrojové kódy

[core] CoroutineOnDemandValueScope: fix exception message when emit/receive while producer is already finished

Him188 2 rokov pred
rodič
commit
578d1a9d48

+ 7 - 2
mirai-core/src/commonMain/kotlin/network/auth/ProducerState.kt

@@ -154,16 +154,21 @@ internal sealed interface ProducerState<T, V> {
 
         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)