mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-06 08:00:10 +08:00
Postpone error reporting in parsing in NewContact
(#1147)
* Add `ParseErrorPacket` for postpone error report * Continue to parse even if an error occurs
This commit is contained in:
parent
6e914f6941
commit
f6fd4de14b
@ -9,6 +9,9 @@
|
||||
|
||||
package net.mamoe.mirai.internal.network
|
||||
|
||||
import net.mamoe.mirai.internal.QQAndroidBot
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
|
||||
/*
|
||||
|
||||
// moved to `mirai-core`
|
||||
@ -40,4 +43,20 @@ internal open class MultiPacketBySequence<out P : Packet>(internal val delegate:
|
||||
override operator fun iterator(): Iterator<P> = delegate.iterator()
|
||||
|
||||
override fun toString(): String = "MultiPacketBySequence"
|
||||
}
|
||||
}
|
||||
|
||||
internal class ParseErrorPacket(
|
||||
val error: Throwable,
|
||||
val direction: Direction = Direction.TO_BOT_LOGGER,
|
||||
) : Packet, Packet.NoLog {
|
||||
enum class Direction {
|
||||
TO_BOT_LOGGER {
|
||||
override fun getLogger(bot: QQAndroidBot): MiraiLogger = bot.logger
|
||||
},
|
||||
TO_NETWORK_LOGGER {
|
||||
override fun getLogger(bot: QQAndroidBot): MiraiLogger = bot.network.logger
|
||||
};
|
||||
|
||||
abstract fun getLogger(bot: QQAndroidBot): MiraiLogger
|
||||
}
|
||||
}
|
||||
|
@ -517,6 +517,9 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
|
||||
// highest priority: pass to listeners (attached by sendAndExpect).
|
||||
if (packet != null && (bot.logger.isEnabled || logger.isEnabled)) {
|
||||
when {
|
||||
packet is ParseErrorPacket -> {
|
||||
packet.direction.getLogger(bot).error(packet.error)
|
||||
}
|
||||
packet is Packet.NoLog -> {
|
||||
// nothing to do
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import net.mamoe.mirai.internal.QQAndroidBot
|
||||
import net.mamoe.mirai.internal.message.contextualBugReportException
|
||||
import net.mamoe.mirai.internal.network.MultiPacketByIterable
|
||||
import net.mamoe.mirai.internal.network.Packet
|
||||
import net.mamoe.mirai.internal.network.ParseErrorPacket
|
||||
import net.mamoe.mirai.internal.network.QQAndroidClient
|
||||
import net.mamoe.mirai.internal.network.protocol.data.proto.Structmsg
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory
|
||||
@ -260,7 +261,11 @@ internal class NewContact {
|
||||
) { // duplicate
|
||||
return@mapNotNull null
|
||||
}
|
||||
handleStruct(struct)
|
||||
try {
|
||||
handleStruct(struct)
|
||||
} catch (e: Throwable) {
|
||||
ParseErrorPacket(e)
|
||||
}
|
||||
}.let { packets ->
|
||||
when {
|
||||
packets.isEmpty() -> null
|
||||
|
Loading…
Reference in New Issue
Block a user