persist error count aside from errors (#2652)

#### Does this PR need a docs update or release note?

- [ ]  No

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #1970
This commit is contained in:
Keepers 2023-02-24 19:43:32 -07:00 committed by GitHub
parent ac4d7d047a
commit 422a05e21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,7 @@ type Backup struct {
// Errors contains all errors aggregated during a backup operation.
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 {