From 881e2db620e46572cddccd09da4c2416ea3eb81c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 20 Jan 2026 06:34:00 -0800 Subject: fix: Use correct column name error_message in last failure query --- internal/storage/sqlite.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'internal') diff --git a/internal/storage/sqlite.go b/internal/storage/sqlite.go index ce62e67..e441fe7 100644 --- a/internal/storage/sqlite.go +++ b/internal/storage/sqlite.go @@ -379,13 +379,13 @@ func (s *Storage) GetAllMonitorStats(ctx context.Context) (map[string]*MonitorSt // Get last failure for each monitor rows, err = s.db.QueryContext(ctx, ` - SELECT monitor_name, timestamp, error + SELECT monitor_name, timestamp, error_message FROM check_results - WHERE status != 'up' AND error != '' + WHERE status != 'up' AND (monitor_name, timestamp) IN ( SELECT monitor_name, MAX(timestamp) FROM check_results - WHERE status != 'up' AND error != '' + WHERE status != 'up' GROUP BY monitor_name ) `) @@ -397,13 +397,15 @@ func (s *Storage) GetAllMonitorStats(ctx context.Context) (map[string]*MonitorSt for rows.Next() { var name string var timestamp time.Time - var errorMsg string + var errorMsg sql.NullString if err := rows.Scan(&name, ×tamp, &errorMsg); err != nil { return nil, fmt.Errorf("failed to scan last failure: %w", err) } if ms, ok := stats[name]; ok { ms.LastFailure = ×tamp - ms.LastFailureError = errorMsg + if errorMsg.Valid { + ms.LastFailureError = errorMsg.String + } } } -- cgit v1.2.3