Skip to content

Commit 05807be

Browse files
committed
Fill in stacktraces in debug mode
1 parent fcc53f8 commit 05807be

File tree

11 files changed

+32
-23
lines changed

11 files changed

+32
-23
lines changed

kotlinx-coroutines-core/common/src/Exceptions.common.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal expect class JobCancellationException(
2323
internal val job: Job
2424
}
2525

26-
internal expect class CoroutinesInternalError(message: String, cause: Throwable) : Error
26+
internal class CoroutinesInternalError(message: String, cause: Throwable) : Error(message, cause)
2727

2828
internal expect fun Throwable.addSuppressedThrowable(other: Throwable)
2929
// For use in tests

kotlinx-coroutines-core/common/src/flow/internal/AbortFlowException.common.kt renamed to kotlinx-coroutines-core/common/src/flow/internal/FlowExceptions.common.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ import kotlinx.coroutines.*
1111
* This exception should never escape outside of operator's implementation.
1212
*/
1313
internal expect class AbortFlowException() : CancellationException
14+
15+
/**
16+
* Exception used to cancel child of [scopedFlow] without cancelling the whole scope.
17+
*/
18+
internal expect class ChildCancelledException() : CancellationException

kotlinx-coroutines-core/common/src/flow/internal/FlowScope.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,3 @@ internal class FlowScope<T, R>(
5656

5757
override suspend fun emit(value: R) = collector.emit(value)
5858
}
59-
60-
internal class ChildCancelledException : CancellationException(null)

kotlinx-coroutines-core/js/src/Exceptions.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ internal actual class JobCancellationException public actual constructor(
4848
(message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
4949
}
5050

51-
internal actual class CoroutinesInternalError actual constructor(message: String, cause: Throwable) : Error(message.withCause(cause))
52-
5351
@Suppress("FunctionName")
5452
internal fun IllegalStateException(message: String, cause: Throwable?) =
5553
IllegalStateException(message.withCause(cause))

kotlinx-coroutines-core/js/src/flow/internal/AbortFlowException.kt renamed to kotlinx-coroutines-core/js/src/flow/internal/FlowExceptions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ package kotlinx.coroutines.flow.internal
77
import kotlinx.coroutines.*
88

99
internal actual class AbortFlowException : CancellationException("Flow was aborted, no more elements needed")
10+
internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled")

kotlinx-coroutines-core/jvm/src/Exceptions.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ internal actual class JobCancellationException public actual constructor(
8080
(message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
8181
}
8282

83-
internal actual class CoroutinesInternalError actual constructor(message: String, cause: Throwable) : Error(message, cause)
84-
8583
@Suppress("NOTHING_TO_INLINE")
8684
internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) =
87-
addSuppressed(other)
85+
addSuppressed(other)

kotlinx-coroutines-core/jvm/src/flow/internal/AbortFlowException.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.flow.internal
6+
7+
import kotlinx.coroutines.*
8+
9+
internal actual class AbortFlowException : CancellationException("Flow was aborted, no more elements needed") {
10+
override fun fillInStackTrace(): Throwable {
11+
if (DEBUG) super.fillInStackTrace()
12+
return this
13+
}
14+
}
15+
16+
internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled") {
17+
override fun fillInStackTrace(): Throwable {
18+
if (DEBUG) super.fillInStackTrace()
19+
return this
20+
}
21+
}

kotlinx-coroutines-core/native/src/Builders.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ private class BlockingCoroutine<T>(
5454
parentContext: CoroutineContext,
5555
private val eventLoop: EventLoop?
5656
) : AbstractCoroutine<T>(parentContext, true) {
57-
override val isCoroutine: Boolean
58-
get() = false // it throws exception to parent instead of cancelling it
57+
override val isScopedCoroutine: Boolean get() = true
5958

6059
@Suppress("UNCHECKED_CAST")
6160
fun joinBlocking(): T = memScoped {

kotlinx-coroutines-core/native/src/Exceptions.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ internal actual class JobCancellationException public actual constructor(
4848
(message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
4949
}
5050

51-
internal actual class CoroutinesInternalError actual constructor(message: String, cause: Throwable) : Error(message.withCause(cause))
52-
5351
@Suppress("FunctionName")
5452
internal fun IllegalStateException(message: String, cause: Throwable?) =
5553
IllegalStateException(message.withCause(cause))

kotlinx-coroutines-core/native/src/flow/internal/AbortFlowException.kt renamed to kotlinx-coroutines-core/native/src/flow/internal/FlowExceptions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ package kotlinx.coroutines.flow.internal
77
import kotlinx.coroutines.*
88

99
internal actual class AbortFlowException : CancellationException("Flow was aborted, no more elements needed")
10+
internal actual class ChildCancelledException : CancellationException("Child of the scoped flow was cancelled")
11+

0 commit comments

Comments
 (0)