From f7f605bb2af236b8fa496c5fb515fea28e536f65 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Thu, 19 Feb 2026 14:06:44 +0100 Subject: [PATCH] Fix hub store.go: log unchecked json.Unmarshal errors, GetInfraBackupMeta error handling --- hub/internal/store/store.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hub/internal/store/store.go b/hub/internal/store/store.go index 0d2f9ff..1b26309 100644 --- a/hub/internal/store/store.go +++ b/hub/internal/store/store.go @@ -123,7 +123,9 @@ func (s *Store) GetNotificationPrefs(customerID string) (*NotificationPrefs, err } var events []string - json.Unmarshal([]byte(eventsJSON), &events) + if err := json.Unmarshal([]byte(eventsJSON), &events); err != nil { + s.logger.Printf("[WARN] Corrupt enabled_events JSON for %s: %v", customerID, err) + } return &NotificationPrefs{ CustomerID: customerID, @@ -214,7 +216,9 @@ func (s *Store) SaveReport(customerID string, reportJSON []byte) error { Status string `json:"status"` } `json:"health"` } - json.Unmarshal(reportJSON, &parsed) + if err := json.Unmarshal(reportJSON, &parsed); err != nil { + s.logger.Printf("[WARN] Cannot parse report fields for denormalization: %v", err) + } var backupSnapshot *string if parsed.Backup.LastSnapshot != nil { @@ -283,7 +287,9 @@ func (s *Store) GetCustomers() ([]CustomerSummary, error) { var report struct { CustomerName string `json:"customer_name"` } - json.Unmarshal([]byte(c.ReportJSON), &report) + if err := json.Unmarshal([]byte(c.ReportJSON), &report); err != nil { + s.logger.Printf("[WARN] Cannot parse customer_name from report JSON for %s: %v", c.CustomerID, err) + } c.CustomerName = report.CustomerName // Parse disk summary @@ -447,7 +453,9 @@ func (s *Store) GetInfraBackupMeta(customerID string) (*InfraBackupMeta, error) Mounts []json.RawMessage `json:"mounts"` } `json:"disk_layout"` } - if json.Unmarshal([]byte(backupJSON), &parsed) == nil { + if err := json.Unmarshal([]byte(backupJSON), &parsed); err != nil { + s.logger.Printf("[WARN] Failed to parse infra backup metadata for %s: %v", customerID, err) + } else { meta.StackCount = len(parsed.DeployedStacks) meta.DiskCount = len(parsed.DiskLayout.Mounts) } @@ -499,7 +507,8 @@ func parseDiskSummary(reportJSON string) string { Percent float64 `json:"percent"` } `json:"storage"` } - json.Unmarshal([]byte(reportJSON), &report) + // ignore parse errors — show "–" on failure + json.Unmarshal([]byte(reportJSON), &report) //nolint:errcheck var parts []string for _, s := range report.Storage {