Skip to content

Commit

Permalink
Merge pull request #32324 from hashicorp/db-sweepers
Browse files Browse the repository at this point in the history
Corrects error handling in sweeper reference documentation
  • Loading branch information
gdavison authored Jul 5, 2023
2 parents c3f249d + 6303fae commit c5ce537
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions docs/running-and-writing-acceptance-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,6 @@ func sweepThings(region string) error {
// Otherwise, do not include it.
if err != nil {
err := fmt.Errorf("reading Example Thing (%s): %w", id, err)
log.Printf("[ERROR] %s", err)
errs = multierror.Append(errs, err)
continue
}
Expand All @@ -1168,24 +1167,25 @@ func sweepThings(region string) error {
return !lastPage
})
if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Example Thing sweep for %s: %s", region, errs)
return nil
}
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("listing Example Thing for %s: %w", region, err))
errs = multierror.Append(errs, fmt.Errorf("listing Example Things for %s: %w", region, err))
}
if err := sweep.SweepOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("sweeping Example Thing for %s: %w", region, err))
}
if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Example Thing sweep for %s: %s", region, errs)
return nil
errs = multierror.Append(errs, fmt.Errorf("sweeping Example Things for %s: %w", region, err))
}
return errs.ErrorOrNil()
}
```
Otherwise, if no paginated SDK call is available:
If no paginated SDK call is available,
consider generating one using the [`listpages` generator](https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/generate/listpages/README.md),
or implement the sweeper as follows:
```go
func sweepThings(region string) error {
Expand All @@ -1204,6 +1204,14 @@ func sweepThings(region string) error {
for {
output, err := conn.ListThings(input)
if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Example Thing sweep for %s: %s", region, errs)
return nil
}
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("listing Example Things for %s: %w", region, err))
return errs.ErrorOrNil()
}
for _, thing := range output.Things {
r := ResourceThing()
Expand All @@ -1222,7 +1230,6 @@ func sweepThings(region string) error {
// Otherwise, do not include it.
if err != nil {
err := fmt.Errorf("reading Example Thing (%s): %w", id, err)
log.Printf("[ERROR] %s", err)
errs = multierror.Append(errs, err)
continue
}
Expand All @@ -1241,11 +1248,6 @@ func sweepThings(region string) error {
errs = multierror.Append(errs, fmt.Errorf("sweeping Example Thing for %s: %w", region, err))
}
if sweep.SkipSweepError(err) {
log.Printf("[WARN] Skipping Example Thing sweep for %s: %s", region, errs)
return nil
}
return errs.ErrorOrNil()
}
```
Expand Down

0 comments on commit c5ce537

Please sign in to comment.