From 0ff218ab3e306f2faea558f17d8587a6eb9652a7 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Thu, 16 Feb 2023 20:32:44 -0800 Subject: [PATCH] Hook into error callback in kopia (#2555) ## Description Using this over extracting errors from the snapshot allows us to see all errors. The errors that each directory tracks are truncated when the directory is serialized for persistence if there're too many. With the current `fault.Errors` behavior this cases the backup to fail if there's any errors kopia ignored. This is consistent with behavior in the backup op that checks for any errors. Unclear what the CLI output and log messages will be for these errors as they are grouped into all other errors reported through the fault package ## Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No ## Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup ## Issue(s) * #2548 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/upload.go | 10 ++++++++++ src/internal/kopia/wrapper_test.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/internal/kopia/upload.go b/src/internal/kopia/upload.go index faa46cea8..302063933 100644 --- a/src/internal/kopia/upload.go +++ b/src/internal/kopia/upload.go @@ -257,6 +257,16 @@ func (cp *corsoProgress) CachedFile(fname string, size int64) { d.cached = true } +// Kopia interface function used as a callback when kopia encounters an error +// during the upload process. This could be from reading a file or something +// else. +func (cp *corsoProgress) Error(relpath string, err error, isIgnored bool) { + defer cp.UploadProgress.Error(relpath, err, isIgnored) + + cp.errs.Add(clues.Wrap(err, "kopia reported error"). + WithAll("is_ignored", isIgnored, "relative_path", relpath)) +} + func (cp *corsoProgress) put(k string, v *itemDetails) { cp.mu.Lock() defer cp.mu.Unlock() diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 8c1505ed3..baa7a5d9b 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -483,7 +483,7 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections_ReaderError() { tags, true, fault.New(true)) - require.NoError(t, err) + require.Error(t, err) assert.Equal(t, 0, stats.ErrorCount) assert.Equal(t, 5, stats.TotalFileCount)