feat: Redis 会话历史解析错误日志截断保护
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hhs/camtalk/internal/logger"
|
"github.com/hhs/camtalk/internal/logger"
|
||||||
"github.com/hhs/camtalk/internal/models"
|
"github.com/hhs/camtalk/internal/models"
|
||||||
|
"github.com/hhs/camtalk/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RedisManager 基于 Redis 的 SessionManager 实现。
|
// RedisManager 基于 Redis 的 SessionManager 实现。
|
||||||
@@ -285,7 +286,10 @@ func (m *RedisManager) GetHistory(ctx context.Context, sessionID string, limit i
|
|||||||
}
|
}
|
||||||
var msg models.Message
|
var msg models.Message
|
||||||
if err := json.Unmarshal([]byte(raw), &msg); err != nil {
|
if err := json.Unmarshal([]byte(raw), &msg); err != nil {
|
||||||
logger.Log.Warnw("invalid history entry", "session", sessionID, "raw", raw)
|
logger.Log.Warnw("invalid history entry",
|
||||||
|
"session", sessionID,
|
||||||
|
"raw_len", len(raw),
|
||||||
|
"raw_preview", util.Truncate(raw, 100))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user