Skip to content

Commit daa473a

Browse files
committed
Fix weird issue on K/N
1 parent d017d88 commit daa473a

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
package kotlinx.rpc.krpc.internal
66

7-
import kotlinx.coroutines.CancellationException
7+
import kotlin.coroutines.cancellation.CancellationException
88
import kotlinx.rpc.internal.rpcInternalTypeName
99
import kotlinx.rpc.internal.utils.InternalRpcApi
1010

@@ -13,8 +13,8 @@ public fun serializeException(cause: Throwable): SerializedException {
1313
val message = cause.message ?: "Unknown exception"
1414
val stacktrace = cause.stackElements()
1515
val serializedCause = cause.cause?.let { serializeException(it) }
16-
val className = if (cause is CancellationException || cause is kotlin.coroutines.cancellation.CancellationException) {
17-
CancellationException::class.rpcInternalTypeName ?: "kotlinx.coroutines.CancellationException"
16+
val className = if (cause is kotlinx.coroutines.CancellationException || cause is CancellationException) {
17+
CancellationException::class.rpcInternalTypeName ?: "kotlin.coroutines.cancellation.CancellationException"
1818
} else {
1919
cause::class.rpcInternalTypeName ?: ""
2020
}
@@ -27,8 +27,8 @@ internal expect fun Throwable.stackElements(): List<StackElement>
2727
internal expect fun SerializedException.deserializeUnsafe(): Throwable
2828

2929
internal fun SerializedException.cancellationExceptionDeserialize(): CancellationException? {
30-
if (className == CancellationException::class.rpcInternalTypeName
31-
|| className == kotlin.coroutines.cancellation.CancellationException::class.rpcInternalTypeName
30+
if (className == kotlinx.coroutines.CancellationException::class.rpcInternalTypeName
31+
|| className == CancellationException::class.rpcInternalTypeName
3232
) {
3333
val cause = this@cancellationExceptionDeserialize.cause?.deserializeUnsafe()
3434

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcReceiveBuffer.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package kotlinx.rpc.krpc.internal
66

77
import kotlinx.atomicfu.atomic
8-
import kotlinx.coroutines.CancellationException
8+
import kotlin.coroutines.cancellation.CancellationException
99
import kotlinx.coroutines.channels.Channel
1010

1111
internal class KrpcReceiveBuffer(
@@ -56,7 +56,13 @@ internal class KrpcReceiveBuffer(
5656

5757
fun close(cause: Throwable?) {
5858
channel.close(cause)
59-
channel.cancel(CancellationException(null, cause))
59+
60+
// There is some cringe here otherwise
61+
// Overload resolution ambiguity between candidates:
62+
// constructor(message: String?, cause: Throwable?): CancellationException
63+
// expect fun CancellationException(message: String?, cause: Throwable?): CancellationException
64+
@Suppress("CAST_NEVER_SUCCEEDS")
65+
channel.cancel(CancellationException(cause) as kotlinx.coroutines.CancellationException)
6066

6167
_inBuffer.getAndSet(_channelSize)
6268
}

krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcReceiveHandler.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package kotlinx.rpc.krpc.internal
66

77
import kotlinx.atomicfu.atomic
8-
import kotlinx.coroutines.CancellationException
8+
import kotlin.coroutines.cancellation.CancellationException
99
import kotlinx.coroutines.CoroutineName
1010
import kotlinx.coroutines.CoroutineStart
1111
import kotlinx.coroutines.launch
@@ -186,10 +186,15 @@ internal class KrpcActingReceiveHandler(
186186

187187
override fun close(key: HandlerKey<*>, e: Throwable?) {
188188
if (e != null) {
189-
if (e is CancellationException) {
189+
if (e is kotlinx.coroutines.CancellationException) {
190190
job.cancel(e)
191191
} else {
192-
job.cancel(CancellationException(null, e))
192+
// There is some cringe here otherwise
193+
// Overload resolution ambiguity between candidates:
194+
// constructor(message: String?, cause: Throwable?): CancellationException
195+
// expect fun CancellationException(message: String?, cause: Throwable?): CancellationException
196+
@Suppress("CAST_NEVER_SUCCEEDS")
197+
job.cancel(CancellationException(e) as kotlinx.coroutines.CancellationException)
193198
}
194199
} else {
195200
job.cancel()

0 commit comments

Comments
 (0)