diff --git a/src/cli/export/export.go b/src/cli/export/export.go index 99200c1f5..caa514331 100644 --- a/src/cli/export/export.go +++ b/src/cli/export/export.go @@ -121,6 +121,16 @@ func runExport( return Only(ctx, err) } + if len(eo.Errors.Recovered()) > 0 { + Infof(ctx, "\nExport failures") + + for _, i := range eo.Errors.Recovered() { + Err(ctx, i.Error()) + } + + return Only(ctx, clues.New("Incomplete export of "+serviceName+" data")) + } + stats := eo.GetStats() if len(stats) > 0 { Infof(ctx, "\nExport details") diff --git a/src/pkg/export/consume.go b/src/pkg/export/consume.go index 02aee9609..19e27baf5 100644 --- a/src/pkg/export/consume.go +++ b/src/pkg/export/consume.go @@ -31,6 +31,7 @@ func ConsumeExportCollections( for item := range col.Items(ictx) { if item.Error != nil { el.AddRecoverable(ictx, clues.Wrap(item.Error, "getting item")) + continue } if err := writeItem(ictx, item, folder); err != nil { diff --git a/src/pkg/export/consume_test.go b/src/pkg/export/consume_test.go index ab94cedcb..b992b726f 100644 --- a/src/pkg/export/consume_test.go +++ b/src/pkg/export/consume_test.go @@ -53,6 +53,7 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() { type ei struct { name string body string + err error } type i struct { @@ -61,9 +62,29 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() { } table := []struct { - name string - cols []i + name string + cols []i + hasError bool }{ + { + name: "items with one error and success", + cols: []i{ + { + path: "", + items: []ei{ + { + name: "name0", + err: assert.AnError, + }, + { + name: "name1", + body: "body1", + }, + }, + }, + }, + hasError: true, + }, { name: "single root collection single item", cols: []i{ @@ -136,6 +157,15 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() { for _, col := range test.cols { items := []Item{} for _, item := range col.items { + if item.err != nil { + items = append(items, Item{ + Name: item.name, + Body: nil, + Error: item.err, + }) + continue + } + items = append(items, Item{ Name: item.name, Body: io.NopCloser((bytes.NewBufferString(item.body))), @@ -153,6 +183,11 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() { defer os.RemoveAll(dir) err = ConsumeExportCollections(ctx, dir, ecs, fault.New(true)) + if test.hasError { + require.Error(t, err) + return + } + require.NoError(t, err, "writing data") for _, col := range test.cols {