diff --git a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt index 55ff9cfb9..ffd5bdea4 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt @@ -51,6 +51,10 @@ internal interface PacketCodec { } } +internal data class ExceptionInPacketCodecException( + override val cause: Throwable, +) : IllegalStateException("Exception in PacketCodec.", cause) + internal class OicqDecodingException( val targetException: Throwable ) : RuntimeException( diff --git a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt index 343afaa27..44daf7c3e 100644 --- a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt @@ -56,9 +56,12 @@ internal open class NettyNetworkHandler( protected open fun handleExceptionInDecoding(error: Throwable) { if (error is OicqDecodingException) { if (error.targetException is EOFException) return - throw error.targetException } - throw error + + coroutineContext[CoroutineExceptionHandler]!!.handleException( + coroutineContext, + ExceptionInPacketCodecException(error.unwrap()) + ) } protected open fun handlePipelineException(ctx: ChannelHandlerContext, error: Throwable) {