Skip to content

Commit 2064693

Browse files
committed
Fill in stacktraces in debug mode
1 parent 369298c commit 2064693

File tree

11 files changed

+32
-23
lines changed

11 files changed

+32
-23
lines changed

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

+1-1
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

+5
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

-2
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

-2
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

+1
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

+1-3
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

-11
This file was deleted.
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ private class BlockingCoroutine<T>(
5252
parentContext: CoroutineContext,
5353
private val eventLoop: EventLoop?
5454
) : AbstractCoroutine<T>(parentContext, true) {
55-
override val isCoroutine: Boolean
56-
get() = false // it throws exception to parent instead of cancelling it
55+
override val isScopedCoroutine: Boolean get() = true
5756

5857
@Suppress("UNCHECKED_CAST")
5958
fun joinBlocking(): T {

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

-2
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

+2
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)