Fix hub store.go: log unchecked json.Unmarshal errors, GetInfraBackupMeta error handling
This commit is contained in:
@@ -123,7 +123,9 @@ func (s *Store) GetNotificationPrefs(customerID string) (*NotificationPrefs, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
var events []string
|
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{
|
return &NotificationPrefs{
|
||||||
CustomerID: customerID,
|
CustomerID: customerID,
|
||||||
@@ -214,7 +216,9 @@ func (s *Store) SaveReport(customerID string, reportJSON []byte) error {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
} `json:"health"`
|
} `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
|
var backupSnapshot *string
|
||||||
if parsed.Backup.LastSnapshot != nil {
|
if parsed.Backup.LastSnapshot != nil {
|
||||||
@@ -283,7 +287,9 @@ func (s *Store) GetCustomers() ([]CustomerSummary, error) {
|
|||||||
var report struct {
|
var report struct {
|
||||||
CustomerName string `json:"customer_name"`
|
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
|
c.CustomerName = report.CustomerName
|
||||||
|
|
||||||
// Parse disk summary
|
// Parse disk summary
|
||||||
@@ -447,7 +453,9 @@ func (s *Store) GetInfraBackupMeta(customerID string) (*InfraBackupMeta, error)
|
|||||||
Mounts []json.RawMessage `json:"mounts"`
|
Mounts []json.RawMessage `json:"mounts"`
|
||||||
} `json:"disk_layout"`
|
} `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.StackCount = len(parsed.DeployedStacks)
|
||||||
meta.DiskCount = len(parsed.DiskLayout.Mounts)
|
meta.DiskCount = len(parsed.DiskLayout.Mounts)
|
||||||
}
|
}
|
||||||
@@ -499,7 +507,8 @@ func parseDiskSummary(reportJSON string) string {
|
|||||||
Percent float64 `json:"percent"`
|
Percent float64 `json:"percent"`
|
||||||
} `json:"storage"`
|
} `json:"storage"`
|
||||||
}
|
}
|
||||||
json.Unmarshal([]byte(reportJSON), &report)
|
// ignore parse errors — show "–" on failure
|
||||||
|
json.Unmarshal([]byte(reportJSON), &report) //nolint:errcheck
|
||||||
|
|
||||||
var parts []string
|
var parts []string
|
||||||
for _, s := range report.Storage {
|
for _, s := range report.Storage {
|
||||||
|
|||||||
Reference in New Issue
Block a user