fix: replace panic calls with proper error handling

Remove 51 panic() calls from handler code and replace with:
- Proper error logging using zap
- Appropriate client error responses (doAckBufFail, doAckSimpleFail)
- Graceful error recovery instead of server crashes

Files updated:
- handlers_guild_scout.go (9 panics)
- handlers_guild_tresure.go (10 panics)
- handlers_guild.go (7 panics + dead code removal)
- handlers_mail.go (5 panics)
- handlers.go (9 panics)
- handlers_tower.go (2 panics)
- handlers_clients.go (3 panics)
- handlers_guild_alliance.go (1 panic)
- handlers_quest.go (1 panic)
- handlers_rengoku.go (1 panic)
- handlers_stage.go (1 panic)
- handlers_data.go (1 panic)
- handlers_cafe.go (1 panic)
- signserver/sign_server.go (1 panic)

Remaining panics (3) are in test files and compression library
where panicking on programming errors is appropriate.
This commit is contained in:
Houmgaor
2026-02-02 17:14:34 +01:00
parent dbc3b21827
commit f138cb5f77
15 changed files with 203 additions and 108 deletions

View File

@@ -258,15 +258,17 @@ func handleMsgMhfReadMail(s *Session, p mhfpacket.MHFPacket) {
mailId := s.mailList[pkt.AccIndex]
if mailId == 0 {
s.logger.Warn("attempting to read mail that doesn't exist in session map", zap.Uint8("accIndex", pkt.AccIndex))
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
panic("attempting to read mail that doesn't exist in session map")
return
}
mail, err := GetMailByID(s, mailId)
if err != nil {
s.logger.Error("failed to get mail by ID", zap.Error(err), zap.Int("mailID", mailId))
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
panic(err)
return
}
_ = mail.MarkRead(s)
@@ -285,8 +287,9 @@ func handleMsgMhfListMail(s *Session, p mhfpacket.MHFPacket) {
mail, err := GetMailListForCharacter(s, s.charID)
if err != nil {
s.logger.Error("failed to get mail list", zap.Error(err), zap.Uint32("charID", s.charID))
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
panic(err)
return
}
if s.mailList == nil {
@@ -354,7 +357,9 @@ func handleMsgMhfOprtMail(s *Session, p mhfpacket.MHFPacket) {
mail, err := GetMailByID(s, s.mailList[pkt.AccIndex])
if err != nil {
panic(err)
s.logger.Error("failed to get mail for operation", zap.Error(err), zap.Uint8("accIndex", pkt.AccIndex))
doAckSimpleFail(s, pkt.AckHandle, nil)
return
}
switch pkt.Operation {
@@ -369,7 +374,9 @@ func handleMsgMhfOprtMail(s *Session, p mhfpacket.MHFPacket) {
}
if err != nil {
panic(err)
s.logger.Error("failed to perform mail operation", zap.Error(err), zap.Uint8("operation", uint8(pkt.Operation)))
doAckSimpleFail(s, pkt.AckHandle, nil)
return
}
doAckSimpleSucceed(s, pkt.AckHandle, make([]byte, 4))