Skip to content

Commit 223168d

Browse files
committed
return non zero code when there is a throttline exception
1 parent 0b661ad commit 223168d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cmd/nuke.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,14 @@ func (n *Nuke) HandleQueue() {
249249
n.HandleRemove(item)
250250
item.Print()
251251
case ItemStateFailed:
252-
n.HandleRemove(item)
253-
n.HandleWait(item, listCache)
254-
item.Print()
252+
// item.Resource will be nil if an exception was thrown while retrieving the resourceType's
253+
// items (I.E resourceTypes lister()), however we still pass down the reason and state so we
254+
// aren't ignoring these exceptions.
255+
if item.Resource != nil {
256+
n.HandleRemove(item)
257+
n.HandleWait(item, listCache)
258+
item.Print()
259+
}
255260
case ItemStatePending:
256261
n.HandleWait(item, listCache)
257262
item.State = ItemStateWaiting

cmd/scan.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"runtime/debug"
77

8+
"github.com/aws/aws-sdk-go/aws/awserr"
89
"github.com/rebuy-de/aws-nuke/v2/pkg/awsutil"
910
"github.com/rebuy-de/aws-nuke/v2/pkg/util"
1011
"github.com/rebuy-de/aws-nuke/v2/resources"
@@ -72,6 +73,21 @@ func (s *scanner) list(region *Region, resourceType string) {
7273
return
7374
}
7475

76+
// check for this error "ThrottlingException: Rate exceeded"
77+
// TODO: if there is a throttling exception call lister(sess) again 3 times with exponential backoff.
78+
// or maybe try recursion and call s.list(region, resourceType)
79+
awsErr, ok := err.(awserr.Error)
80+
if ok && awsErr.Code() == "ThrottlingException" {
81+
s.items <- &Item{
82+
Region: region,
83+
Resource: nil,
84+
State: ItemStateFailed,
85+
Reason: err.Error(),
86+
Type: resourceType,
87+
}
88+
return
89+
}
90+
7591
dump := util.Indent(fmt.Sprintf("%v", err), " ")
7692
log.Errorf("Listing %s failed:\n%s", resourceType, dump)
7793
return

0 commit comments

Comments
 (0)