Fix hub store.go: log unchecked json.Unmarshal errors, GetInfraBackupMeta error handling

This commit is contained in:
2026-02-19 14:06:44 +01:00
parent 41e313bf36
commit f7f605bb2a
+14 -5
View File
@@ -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 {