1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

feat: dump packet on decoder panic

This commit is contained in:
Mrs4s 2021-12-16 15:26:07 +08:00
parent 6c1b622107
commit 5a59cc656c
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
3 changed files with 10 additions and 0 deletions

View File

@ -177,6 +177,7 @@ type (
LogEvent struct { LogEvent struct {
Type string Type string
Message string Message string
Dump []byte
} }
ServerUpdatedEvent struct { ServerUpdatedEvent struct {

View File

@ -723,3 +723,11 @@ func (c *QQClient) Trace(msg string, args ...interface{}) {
Message: fmt.Sprintf(msg, args...), Message: fmt.Sprintf(msg, args...),
}) })
} }
func (c *QQClient) Dump(msg string, data []byte, args ...interface{}) {
c.dispatchLogEvent(&LogEvent{
Type: "DUMP",
Message: fmt.Sprintf(msg, args...),
Dump: data,
})
}

View File

@ -322,6 +322,7 @@ func (c *QQClient) netLoop() {
defer func() { defer func() {
if pan := recover(); pan != nil { if pan := recover(); pan != nil {
c.Error("panic on decoder %v : %v\n%s", pkt.CommandName, pan, debug.Stack()) c.Error("panic on decoder %v : %v\n%s", pkt.CommandName, pan, debug.Stack())
c.Dump("packet decode error: %v - %v", pkt.Payload, pkt.CommandName, pan)
} }
}() }()