Skip to content

Commit

Permalink
🐛 Report violations for ruleset with errors. (#112)
Browse files Browse the repository at this point in the history
In support of succeeded-with-errors, the addon should report issues
(violations) even when the ruleset reports errors.

Also fixes duplicate rule errors added to the Task.Errors.

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Jul 16, 2024
1 parent 3f0aed6 commit a35f376
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion builder/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (b *Deps) Write(writer io.Writer) (err error) {
encoder := yaml.NewEncoder(writer)
for _, p := range input {
for _, d := range p.Dependencies {
_ = encoder.Encode(
err = encoder.Encode(
&api.TechDependency{
Provider: p.Provider,
Indirect: d.Indirect,
Expand All @@ -49,6 +49,9 @@ func (b *Deps) Write(writer io.Writer) (err error) {
SHA: d.ResolvedIdentifier,
Labels: d.Labels,
})
if err != nil {
return
}
}
}
return
Expand Down
14 changes: 8 additions & 6 deletions builder/issue.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builder

import (
"errors"
"fmt"
"io"
"net/url"
Expand Down Expand Up @@ -51,9 +52,6 @@ func (b *Issues) Write(writer io.Writer) (err error) {
encoder := yaml.NewEncoder(writer)
for _, ruleset := range input {
b.ruleErr.Append(ruleset)
if b.ruleErr.NotEmpty() {
continue
}
for ruleid, v := range ruleset.Violations {
issue := api.Issue{
RuleSet: ruleset.Name,
Expand Down Expand Up @@ -89,7 +87,10 @@ func (b *Issues) Write(writer io.Writer) (err error) {
issue.Incidents,
incident)
}
_ = encoder.Encode(&issue)
err = encoder.Encode(&issue)
if err != nil {
return
}
}
}
if err != nil {
Expand Down Expand Up @@ -157,7 +158,8 @@ func (e *RuleError) Error() (s string) {
}

func (e *RuleError) Is(err error) (matched bool) {
_, matched = err.(*RuleError)
var ruleError *RuleError
matched = errors.As(err, &ruleError)
return
}

Expand All @@ -184,6 +186,6 @@ func (e *RuleError) Report() {
Severity: "Error",
Description: fmt.Sprintf("[Analyzer] %s: %s", ruleid, err),
})
addon.Error(errors...)
}
addon.Error(errors...)
}

0 comments on commit a35f376

Please sign in to comment.