feat(quality): Q5 后端错误处理治理扩展 — RDP/API Token/AIOps 模块 8 处 _ = DB 写入改为 log.Printf
Q4 修复了 controller/ 层 8 处 DB 写入的 _ = 静默忽略,但后续合并的 RDP
远程桌面、API Token、AIOps 告警分析等模块引入了新的 _ = DB 写入忽略。
本次将 controller/middleware 层所有 DB 写入操作(Create/Update/Updates)
的 _ = 静默忽略改为带 log.Printf 错误日志(不阻断业务流程)。
修改文件 (6):
- middleware/auth.go: API 密钥最后使用时间更新
- controller/terminal_session.go: 终端回放审计日志 + 修复 log 变量遮蔽
- controller/user_api_token.go: API 密钥默认值补全
- controller/rdp.go: RDP 会话结束状态 + 命令记录
- controller/rdp_session.go: 会话终止 + 回放审计 + 修复 log 变量遮蔽
- controller/aiops_alert_analysis.go: AI 告警分析结果保存
修复 2 处 Go 变量名遮蔽陷阱(log := model.AuditLog{} 遮蔽 "log" 包 → auditLog)
保留 4 处可接受忽略(1 DB 读取 + 3 WebSocket 帧写入)
验证: go build=0, 17/17 集成测试通过, Docker healthy
This commit is contained in:
1 parent
da9fd1e987
commit
cd30af5bd6
8 files changed
+63
-11
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -398,7 +399,9 @@ func (h *AIOpsAlertAnalysisHandler) saveAnalysisTrace(ctx context.Context, in an
|
||||
Duration: in.Duration,
|
||||
Error: in.Error,
|
||||
}
|
||||
_ = h.db.WithContext(ctx).Create(&row).Error
|
||||
if err := h.db.WithContext(ctx).Create(&row).Error; err != nil {
|
||||
log.Printf("[AIOpsAnalysis] 保存告警分析结果失败 (alert_id=%s, provider=%s): %v", in.AlertID, in.Provider, err)
|
||||
}
|
||||
}
|
||||
|
||||
func marshalTraceJSON(v interface{}) string {
|
||||
|
||||
Reference in new issue
Block a user