From 3613fd5732731c51a29b6048e8d3eb77e84c0d0c Mon Sep 17 00:00:00 2001 From: Niklas Ye Date: Thu, 8 Oct 2026 09:00:54 +0200 Subject: [PATCH] Check rows.Err() in the remaining Next() loops (#27) Incident list, the three stats breakdowns and the user list could return a truncated result as if complete when the scan failed partway. --- internal/api/incidents.go | 4 ++++ internal/api/stats.go | 12 ++++++++++++ internal/api/users.go | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/internal/api/incidents.go b/internal/api/incidents.go index a1576d5..f0aa6f1 100644 --- a/internal/api/incidents.go +++ b/internal/api/incidents.go @@ -100,6 +100,10 @@ func handleListIncidents(db *sql.DB) http.HandlerFunc { } incidents = append(incidents, i) } + if err := rows.Err(); err != nil { + respond(w, http.StatusInternalServerError, errResp("internal error")) + return + } respond(w, http.StatusOK, incidents) } } diff --git a/internal/api/stats.go b/internal/api/stats.go index bd55be6..ee30af9 100644 --- a/internal/api/stats.go +++ b/internal/api/stats.go @@ -73,6 +73,10 @@ func handleStatsTop(db *sql.DB) http.HandlerFunc { } result = append(result, e) } + if err := rows.Err(); err != nil { + respond(w, http.StatusInternalServerError, errResp("internal error")) + return + } respond(w, http.StatusOK, result) } } @@ -104,6 +108,10 @@ func handleStatsByHour(db *sql.DB) http.HandlerFunc { } counts[hr] = cnt } + if err := rows.Err(); err != nil { + respond(w, http.StatusInternalServerError, errResp("internal error")) + return + } type entry struct { Hour int `json:"hour"` @@ -146,6 +154,10 @@ func handleStatsByDay(db *sql.DB) http.HandlerFunc { } counts[dow] = cnt } + if err := rows.Err(); err != nil { + respond(w, http.StatusInternalServerError, errResp("internal error")) + return + } dayNames := [7]string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} type entry struct { diff --git a/internal/api/users.go b/internal/api/users.go index 93c7c15..aa457a2 100644 --- a/internal/api/users.go +++ b/internal/api/users.go @@ -116,6 +116,10 @@ func handleListUsers(db *sql.DB) http.HandlerFunc { u.DisabledAt = unixPtr(disabled) users = append(users, u) } + if err := rows.Err(); err != nil { + respond(w, http.StatusInternalServerError, errResp("internal error")) + return + } respond(w, http.StatusOK, users) } }