Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrects error handling in sweeper reference documentation #32324

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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