Skip to content

Commit

Permalink
fix: corrects the use of errors.Join
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Nov 25, 2024
1 parent 68831db commit cd235ef
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rules/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ func (m *MemoryStore) FindByComponent(ctx context.Context, componentId string) (
}

var ruleSets []extensions.RuleSet
var errs error
var errs []error
for ruleId := range ruleIds {
ruleSet, err := m.GetByRuleID(ctx, ruleId)
errs = errors.Join(err)
if err != nil {
errs = append(errs, err)
}

// Make sure we are only returning the relevant checks for this
// component.
Expand All @@ -185,8 +187,9 @@ func (m *MemoryStore) FindByComponent(ctx context.Context, componentId string) (
ruleSets = append(ruleSets, ruleSet)
}

if errs != nil {
return ruleSets, fmt.Errorf("failed to find rules for component %q: %w", componentId, errs)
if len(errs) > 0 {
joinedErr := errors.Join(errs...)
return ruleSets, fmt.Errorf("failed to find rules for component %q: %w", componentId, joinedErr)
}

return ruleSets, nil
Expand Down

0 comments on commit cd235ef

Please sign in to comment.