Skip to content

Commit

Permalink
fix: do not throw an error, revert to log and continue
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Oct 20, 2024
1 parent 5828746 commit 1ca69ff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ func (f Filters) Match(resourceType string, p Property) (bool, error) {
for _, filter := range groupFilters {
prop, err := p.GetProperty(filter.Property)
if err != nil {
// Note: this continues because we want it to continue if a property is not found for the time
// being. This can also return an error we want as a warning if a resource does not support
// custom properties. This can be triggered by __global__ filters that are applied to all resources.
logrus.WithError(err).Warn("error getting property")
return false, err
continue
}

match, err := filter.Match(prop)
Expand Down
3 changes: 2 additions & 1 deletion pkg/filter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func TestFilter_MatchGroup(t *testing.T) {
},
},
filtered: false,
error: true,
// TODO: add in log handler checks for error as this throws a warning
error: false,
},
{
name: "single-group-invalid-type",
Expand Down
6 changes: 5 additions & 1 deletion pkg/nuke/nuke.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,11 @@ func (n *Nuke) filterWithoutGroups(item *queue.Item) error {

prop, err := item.GetProperty(f.Property)
if err != nil {
return err
// Note: this needs to remain a warning. There needs to be additional logic and handling for
// properties that do not exist if we wish to do something about it. Additionally, the __global__ is
// a special case that is used to filter all resources.
log.WithError(err).Warnf("unable to get property: %s", f.Property)
continue
}

log.Tracef("property: %s", prop)
Expand Down
7 changes: 5 additions & 2 deletions pkg/nuke/nuke_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ func Test_Nuke_Filters_ErrorCustomProps(t *testing.T) {
assert.NoError(t, sErr)

err := n.Scan(context.TODO())
assert.Error(t, err)
assert.Equal(t, "*nuke.TestResource does not support custom properties", err.Error())
assert.NoError(t, err)

assert.Equal(t, 1, n.Queue.Total())
assert.Equal(t, 1, n.Queue.Count(queue.ItemStateNew))
assert.Equal(t, 0, n.Queue.Count(queue.ItemStateFiltered))
}

type TestResourceFilter struct {
Expand Down

0 comments on commit 1ca69ff

Please sign in to comment.