Do not try to export items with error (#4867)

<!-- PR description-->

---

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

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2023-12-18 12:38:57 +05:30 committed by GitHub
parent b57115b353
commit 83d9492b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View File

@ -121,6 +121,16 @@ func runExport(
return Only(ctx, err) 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() stats := eo.GetStats()
if len(stats) > 0 { if len(stats) > 0 {
Infof(ctx, "\nExport details") Infof(ctx, "\nExport details")

View File

@ -31,6 +31,7 @@ func ConsumeExportCollections(
for item := range col.Items(ictx) { for item := range col.Items(ictx) {
if item.Error != nil { if item.Error != nil {
el.AddRecoverable(ictx, clues.Wrap(item.Error, "getting item")) el.AddRecoverable(ictx, clues.Wrap(item.Error, "getting item"))
continue
} }
if err := writeItem(ictx, item, folder); err != nil { if err := writeItem(ictx, item, folder); err != nil {

View File

@ -53,6 +53,7 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() {
type ei struct { type ei struct {
name string name string
body string body string
err error
} }
type i struct { type i struct {
@ -61,9 +62,29 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() {
} }
table := []struct { table := []struct {
name string name string
cols []i 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", name: "single root collection single item",
cols: []i{ cols: []i{
@ -136,6 +157,15 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() {
for _, col := range test.cols { for _, col := range test.cols {
items := []Item{} items := []Item{}
for _, item := range col.items { 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{ items = append(items, Item{
Name: item.name, Name: item.name,
Body: io.NopCloser((bytes.NewBufferString(item.body))), Body: io.NopCloser((bytes.NewBufferString(item.body))),
@ -153,6 +183,11 @@ func (suite *ExportE2ESuite) TestConsumeExportCollection() {
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
err = ConsumeExportCollections(ctx, dir, ecs, fault.New(true)) err = ConsumeExportCollections(ctx, dir, ecs, fault.New(true))
if test.hasError {
require.Error(t, err)
return
}
require.NoError(t, err, "writing data") require.NoError(t, err, "writing data")
for _, col := range test.cols { for _, col := range test.cols {