Procházet zdrojové kódy

Do not throw exception from PacketCodec but log with `CoroutineExceptionHandler`

Him188 před 4 roky
rodič
revize
5aae46218f

+ 4 - 0
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(

+ 5 - 2
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<OicqDecodingException>())
+        )
     }
 
     protected open fun handlePipelineException(ctx: ChannelHandlerContext, error: Throwable) {