From 0be38909dd2fc4eba13f1aba08ba0298dfb953a7 Mon Sep 17 00:00:00 2001 From: Keepers Date: Thu, 2 Feb 2023 23:18:41 -0700 Subject: [PATCH] handle error from bu.backupCollections (#2386) ## Does this PR need a docs update or release note? - [x] :no_entry: No ## Type of change - [x] :bug: Bugfix ## Test Plan - [x] :green_heart: E2E --- src/internal/operations/backup.go | 36 +++++++++++++++++------------- src/internal/operations/restore.go | 6 +++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index e0df72d55..e6b8c767a 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -167,6 +167,12 @@ func (op *BackupOperation) do(ctx context.Context) (err error) { // persist operation results to the model store on exit defer func() { + // panic recovery here prevents additional errors in op.persistResults() + if r := recover(); r != nil { + err = clues.Wrap(r.(error), "panic recovery").WithClues(ctx).With("stacktrace", debug.Stack()) + return + } + err = op.persistResults(startTime, &opStats) if err != nil { op.Errors.Fail(errors.Wrap(err, "persisting backup results")) @@ -445,24 +451,22 @@ func consumeBackupDataCollections( cs, nil, tags, - isIncremental, - ) + isIncremental) + if err != nil { + if kopiaStats == nil { + return nil, nil, nil, err + } + + return nil, nil, nil, errors.Wrapf( + err, + "kopia snapshot failed with %v catastrophic errors and %v ignored errors", + kopiaStats.ErrorCount, kopiaStats.IgnoredErrorCount) + } if kopiaStats.ErrorCount > 0 || kopiaStats.IgnoredErrorCount > 0 { - if err != nil { - err = errors.Wrapf( - err, - "kopia snapshot failed with %v catastrophic errors and %v ignored errors", - kopiaStats.ErrorCount, - kopiaStats.IgnoredErrorCount, - ) - } else { - err = errors.Errorf( - "kopia snapshot failed with %v catastrophic errors and %v ignored errors", - kopiaStats.ErrorCount, - kopiaStats.IgnoredErrorCount, - ) - } + err = errors.Errorf( + "kopia snapshot failed with %v catastrophic errors and %v ignored errors", + kopiaStats.ErrorCount, kopiaStats.IgnoredErrorCount) } return kopiaStats, deets, itemsSourcedFromBase, err diff --git a/src/internal/operations/restore.go b/src/internal/operations/restore.go index cd52e5be3..f90e3c3c8 100644 --- a/src/internal/operations/restore.go +++ b/src/internal/operations/restore.go @@ -151,6 +151,12 @@ func (op *RestoreOperation) do(ctx context.Context) (restoreDetails *details.Det ) defer func() { + // panic recovery here prevents additional errors in op.persistResults() + if r := recover(); r != nil { + err = clues.Wrap(r.(error), "panic recovery").WithClues(ctx).With("stacktrace", debug.Stack()) + return + } + err = op.persistResults(ctx, startTime, &opStats) if err != nil { return