diff options
| author | Fuwn <[email protected]> | 2026-01-20 06:34:00 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 06:34:00 -0800 |
| commit | 881e2db620e46572cddccd09da4c2416ea3eb81c (patch) | |
| tree | 9e42611460483c4a4a22a6d0613c3dabe0517cb7 | |
| parent | feat: Add uptime tooltip showing last failure time and reason (diff) | |
| download | kaze-881e2db620e46572cddccd09da4c2416ea3eb81c.tar.xz kaze-881e2db620e46572cddccd09da4c2416ea3eb81c.zip | |
fix: Use correct column name error_message in last failure query
| -rw-r--r-- | internal/storage/sqlite.go | 12 |
1 files changed, 7 insertions, 5 deletions
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 + } } } |