diff --git a/src/pkg/backup/backup.go b/src/pkg/backup/backup.go index 2cd08bc1c..cbf15bb6a 100644 --- a/src/pkg/backup/backup.go +++ b/src/pkg/backup/backup.go @@ -37,7 +37,8 @@ type Backup struct { Version int `json:"version"` // Errors contains all errors aggregated during a backup operation. - Errors fault.ErrorsData `json:"errors"` + Errors fault.ErrorsData `json:"errors"` + ErrorCount int `json:"errorCount"` // stats are embedded so that the values appear as top-level properties stats.Errs // Deprecated, replaced with Errors. @@ -56,6 +57,13 @@ func New( se stats.StartAndEndTime, errs *fault.Errors, ) *Backup { + errData := errs.Data() + + errCount := len(errs.Data().Errs) + if errData.Err != nil { + errCount++ + } + return &Backup{ BaseModel: model.BaseModel{ ID: id, @@ -68,7 +76,8 @@ func New( DetailsID: detailsID, Status: status, Selector: selector, - Errors: errs.Data(), + Errors: errData, + ErrorCount: errCount, ReadWrites: rw, StartAndEndTime: se, Version: version.Backup, @@ -114,7 +123,7 @@ type Printable struct { func (b Backup) MinimumPrintable() any { return Printable{ ID: b.ID, - ErrorCount: b.errorCount(), + ErrorCount: b.countErrors(), StartedAt: b.StartedAt, Status: b.Status, Version: "0", @@ -138,7 +147,7 @@ func (b Backup) Headers() []string { // Values returns the values matching the Headers list for printing // out to a terminal in a columnar display. func (b Backup) Values() []string { - status := fmt.Sprintf("%s (%d errors)", b.Status, b.errorCount()) + status := fmt.Sprintf("%s (%d errors)", b.Status, b.countErrors()) return []string{ common.FormatTabularDisplayTime(b.StartedAt), @@ -148,8 +157,11 @@ func (b Backup) Values() []string { } } -func (b Backup) errorCount() int { - var errCount int +func (b Backup) countErrors() int { + errCount := b.ErrorCount + if errCount > 0 { + return errCount + } // current tracking if b.ReadErrors != nil || b.WriteErrors != nil {