Do not throw exception from PacketCodec but log with CoroutineExceptionHandler

This commit is contained in:
Him188 2021-07-02 01:08:41 +08:00
parent b90f86258c
commit 5aae46218f
2 changed files with 9 additions and 2 deletions

View File

@ -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(

View File

@ -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) {