Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reconcile error handling #1080

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions upstream/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
dutil "github.com/flanksource/duty/db"
"github.com/flanksource/duty/models"
"github.com/samber/lo"
"github.com/samber/oops"
"github.com/sethvargo/go-retry"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -47,10 +48,10 @@ var (
)

type ReconcileTableSummary struct {
Success int `json:"success,omitempty"`
FKeyError int `json:"foreign_error,omitempty"`
Skipped bool `json:"skipped,omitempty"`
Error error `json:"error,omitempty"`
Success int `json:"success,omitempty"`
FKeyError int `json:"foreign_error,omitempty"`
Skipped bool `json:"skipped,omitempty"`
Error oops.OopsError `json:"error,omitempty"`
}

type ReconcileSummary map[string]ReconcileTableSummary
Expand All @@ -72,7 +73,7 @@ func (t ReconcileSummary) DidReconcile(tables []string) bool {
return false // this table hasn't been reconciled yet
}

reconciled := !summary.Skipped && summary.Error == nil && summary.FKeyError == 0
reconciled := !summary.Skipped && summary.Error.Unwrap() != nil && summary.FKeyError == 0
if !reconciled {
return false // table didn't reconcile successfully
}
Expand Down Expand Up @@ -114,14 +115,17 @@ func (t *ReconcileSummary) AddStat(table string, success, failed int, err error)
v := (*t)[table]
v.Success = success
v.FKeyError = failed
v.Error = err
if err != nil {
// For json marshaling
v.Error = oops.Wrap(err).(oops.OopsError)
}
(*t)[table] = v
}

func (t ReconcileSummary) Error() error {
var allErrors []string
for table, summary := range t {
if summary.Error != nil {
if summary.Error.Unwrap() != nil {
allErrors = append(allErrors, fmt.Sprintf("%s: %s; ", table, summary.Error))
}
}
Expand Down
Loading