fix(handlers): add rows.Err() checks after all scan loops #865

Merged
devops-engineer merged 1 commits from fix/handlers-rows-err-checks into staging 2026-05-13 18:15:44 +00:00
6 changed files with 34 additions and 0 deletions

View File

@ -116,6 +116,9 @@ func (h *ApprovalsHandler) ListAll(c *gin.Context) {
"created_at": createdAt,
})
}
if err := rows.Err(); err != nil {
log.Printf("ListPendingApprovals scan error: %v", err)
}
c.JSON(http.StatusOK, approvals)
}
@ -155,6 +158,9 @@ func (h *ApprovalsHandler) List(c *gin.Context) {
"created_at": createdAt,
})
}
if err := rows.Err(); err != nil {
log.Printf("ListApprovals scan error: %v", err)
}
c.JSON(http.StatusOK, approvals)
}

View File

@ -645,6 +645,9 @@ func (h *DelegationHandler) ListDelegations(c *gin.Context) {
}
delegations = append(delegations, entry)
}
if err := rows.Err(); err != nil {
log.Printf("ListDelegations scan error: %v", err)
}
if delegations == nil {
delegations = []map[string]interface{}{}

View File

@ -352,6 +352,9 @@ func queryPeerMaps(query string, args ...interface{}) ([]map[string]interface{},
result = append(result, peer)
}
if err := rows.Err(); err != nil {
log.Printf("queryPeerMaps scan error: %v", err)
}
return result, nil
}

View File

@ -49,6 +49,9 @@ func (h *EventsHandler) List(c *gin.Context) {
"created_at": createdAt,
})
}
if err := rows.Err(); err != nil {
log.Printf("ListEvents scan error: %v", err)
}
c.JSON(http.StatusOK, events)
}
@ -87,5 +90,8 @@ func (h *EventsHandler) ListByWorkspace(c *gin.Context) {
"created_at": createdAt,
})
}
if err := rows.Err(); err != nil {
log.Printf("ListEventsByWorkspace scan error: %v", err)
}
c.JSON(http.StatusOK, events)
}

View File

@ -248,6 +248,9 @@ func (h *InstructionsHandler) Resolve(c *gin.Context) {
b.WriteString(content)
b.WriteString("\n\n")
}
if err := rows.Err(); err != nil {
log.Printf("ListInstructions scan error: %v", err)
}
c.JSON(http.StatusOK, gin.H{
"workspace_id": workspaceID,
@ -258,6 +261,7 @@ func (h *InstructionsHandler) Resolve(c *gin.Context) {
func scanInstructions(rows interface {
Next() bool
Scan(dest ...interface{}) error
Err() error
}) []Instruction {
var instructions []Instruction
for rows.Next() {
@ -269,6 +273,9 @@ func scanInstructions(rows interface {
}
instructions = append(instructions, inst)
}
if err := rows.Err(); err != nil {
log.Printf("Instructions scan loop error: %v", err)
}
if instructions == nil {
instructions = []Instruction{}
}

View File

@ -63,6 +63,9 @@ func (h *SecretsHandler) List(c *gin.Context) {
"updated_at": updatedAt,
})
}
if err := rows.Err(); err != nil {
log.Printf("ListSecrets scan error: %v", err)
}
// 2. Global secrets not overridden at workspace level
globalRows, err := db.DB.QueryContext(ctx,
@ -324,6 +327,9 @@ func (h *SecretsHandler) ListGlobal(c *gin.Context) {
"scope": "global",
})
}
if err := rows.Err(); err != nil {
log.Printf("ListGlobalSecrets scan error: %v", err)
}
c.JSON(http.StatusOK, secrets)
}
@ -400,6 +406,9 @@ func (h *SecretsHandler) restartAllAffectedByGlobalKey(key string) {
ids = append(ids, id)
}
}
if err := rows.Err(); err != nil {
log.Printf("notifyGlobalSecretChange scan error: %v", err)
}
if len(ids) == 0 {
return
}