mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 09:33:02 +01:00
fix(channelserver): handle silently swallowed DB scan and exec errors
Several handlers discarded errors from rows.Scan() and db.Exec(), masking data corruption or connection issues. Scan failures in diva schedule, event quests, and trend weapons are now logged or returned. InitializeWarehouse now surfaces its insert error to the caller.
This commit is contained in:
@@ -84,7 +84,9 @@ func handleMsgMhfGetUdSchedule(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
} else {
|
} else {
|
||||||
defer func() { _ = rows.Close() }()
|
defer func() { _ = rows.Close() }()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
_ = rows.Scan(&id, &start)
|
if err := rows.Scan(&id, &start); err != nil {
|
||||||
|
s.logger.Error("Failed to scan diva schedule row", zap.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,7 +330,9 @@ func handleMsgMhfAcquireTitle(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgMhfResetTitle(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgMhfResetTitle(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func initializeWarehouse(s *Session) {
|
func initializeWarehouse(s *Session) {
|
||||||
s.server.houseRepo.InitializeWarehouse(s.charID)
|
if err := s.server.houseRepo.InitializeWarehouse(s.charID); err != nil {
|
||||||
|
s.logger.Error("Failed to initialize warehouse", zap.Error(err), zap.Uint32("charID", s.charID))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgMhfOperateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfOperateWarehouse(s *Session, p mhfpacket.MHFPacket) {
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ func TestOperateWarehouse_Op0_GetBoxNames(t *testing.T) {
|
|||||||
_, _, session, charID := setupHouseTest(t)
|
_, _, session, charID := setupHouseTest(t)
|
||||||
|
|
||||||
// Initialize warehouse and rename a box
|
// Initialize warehouse and rename a box
|
||||||
session.server.houseRepo.InitializeWarehouse(charID)
|
_ = session.server.houseRepo.InitializeWarehouse(charID)
|
||||||
_ = session.server.houseRepo.RenameWarehouseBox(charID, 0, 0, "MyItems")
|
_ = session.server.houseRepo.RenameWarehouseBox(charID, 0, 0, "MyItems")
|
||||||
|
|
||||||
pkt := &mhfpacket.MsgMhfOperateWarehouse{
|
pkt := &mhfpacket.MsgMhfOperateWarehouse{
|
||||||
|
|||||||
@@ -261,7 +261,10 @@ func handleMsgMhfGetTrendWeapon(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
j := 0
|
j := 0
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
trendWeapons[i][j].WeaponType = i
|
trendWeapons[i][j].WeaponType = i
|
||||||
_ = rows.Scan(&trendWeapons[i][j].WeaponID)
|
if err := rows.Scan(&trendWeapons[i][j].WeaponID); err != nil {
|
||||||
|
s.logger.Error("Failed to scan trend weapon", zap.Error(err))
|
||||||
|
break
|
||||||
|
}
|
||||||
j++
|
j++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,9 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
|||||||
var questId, activeDuration, inactiveDuration, flags int
|
var questId, activeDuration, inactiveDuration, flags int
|
||||||
var maxPlayers, questType uint8
|
var maxPlayers, questType uint8
|
||||||
var startTime time.Time
|
var startTime time.Time
|
||||||
_ = rows.Scan(&id, &maxPlayers, &questType, &questId, &mark, &flags, &startTime, &activeDuration, &inactiveDuration)
|
if err := rows.Scan(&id, &maxPlayers, &questType, &questId, &mark, &flags, &startTime, &activeDuration, &inactiveDuration); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to scan event quest row: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
data := loadQuestFile(s, questId)
|
data := loadQuestFile(s, questId)
|
||||||
if data == nil {
|
if data == nil {
|
||||||
|
|||||||
@@ -97,12 +97,14 @@ func (r *HouseRepository) UpdateMission(charID uint32, data []byte) error {
|
|||||||
// Warehouse methods
|
// Warehouse methods
|
||||||
|
|
||||||
// InitializeWarehouse ensures a warehouse row exists for the character.
|
// InitializeWarehouse ensures a warehouse row exists for the character.
|
||||||
func (r *HouseRepository) InitializeWarehouse(charID uint32) {
|
func (r *HouseRepository) InitializeWarehouse(charID uint32) error {
|
||||||
var t int
|
var t int
|
||||||
err := r.db.QueryRow(`SELECT character_id FROM warehouse WHERE character_id=$1`, charID).Scan(&t)
|
err := r.db.QueryRow(`SELECT character_id FROM warehouse WHERE character_id=$1`, charID).Scan(&t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, _ = r.db.Exec(`INSERT INTO warehouse (character_id) VALUES ($1)`, charID)
|
_, err = r.db.Exec(`INSERT INTO warehouse (character_id) VALUES ($1)`, charID)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const warehouseNamesSQL = `
|
const warehouseNamesSQL = `
|
||||||
|
|||||||
Reference in New Issue
Block a user