Skip to content

Commit

Permalink
✨ Improved analyzer errors reporting. (#25)
Browse files Browse the repository at this point in the history
Appends analyzer reported errors to the TaskReport.Errors.
Prevent downloading duplicate rulesets.
closes: #26

---------

Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel authored Jul 16, 2023
1 parent da14b3a commit eb5eea7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
19 changes: 9 additions & 10 deletions builder/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (b *Issues) Facts() (facts api.FactMap) {
// RuleError reported by the analyzer.
type RuleError struct {
hub.SoftError
items []string
items map[string]string
}

func (e *RuleError) Error() (s string) {
Expand All @@ -165,8 +165,12 @@ func (e *RuleError) Is(err error) (matched bool) {
}

func (e *RuleError) Append(ruleset output.RuleSet) {
for s, _ := range ruleset.Errors {
e.items = append(e.items, s)
if e.items == nil {
e.items = make(map[string]string)
}
for ruleid, err := range ruleset.Errors {
ruleid := ruleset.Name + "." + ruleid
e.items[ruleid] = err
}
}

Expand All @@ -175,12 +179,7 @@ func (e *RuleError) NotEmpty() (b bool) {
}

func (e *RuleError) Report() {
if len(e.items) == 0 {
return
}
addon.Activity("Analyzer reported:")
for _, s := range e.items {
addon.Activity("> [ERROR] %s.", s)
addon.Error("Error", s)
for ruleid, err := range e.items {
addon.Error("Error", "[Analyzer] %s: %s", ruleid, err)
}
}
7 changes: 0 additions & 7 deletions cmd/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"github.com/konveyor/tackle2-addon-analyzer/builder"
"github.com/konveyor/tackle2-addon/command"
"path"
Expand All @@ -26,12 +25,6 @@ func (r *Analyzer) Run() (b *builder.Issues, err error) {
}
b = &builder.Issues{Path: output}
err = cmd.Run()
if err != nil {
if errors.Is(err, &RuleError{}) {
err.(*RuleError).Report()
}
return
}
return
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"github.com/gin-gonic/gin/binding"
"github.com/konveyor/tackle2-addon/ssh"
hub "github.com/konveyor/tackle2-hub/addon"
Expand Down Expand Up @@ -117,6 +118,11 @@ func main() {
if err == nil {
addon.Activity("Analysis reported. duration: %s", time.Since(mark))
} else {
ruleErr := &RuleError{}
if errors.As(err, &ruleErr) {
ruleErr.Report()
err = nil
}
return
}
//
Expand Down
7 changes: 6 additions & 1 deletion cmd/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ func (r *Rules) addFiles() (err error) {
}

//
// addRuleSets adds rulesets.
// addRuleSets adds rulesets and their dependencies.
func (r *Rules) addRuleSets() (err error) {
history := make(map[uint]byte)
var add func(refs []api.Ref, dep bool)
add = func(refs []api.Ref, dep bool) {
for _, ref := range refs {
if _, found := history[ref.ID]; found {
continue
}
history[ref.ID] = 0
var ruleset *api.RuleSet
ruleset, err = addon.RuleSet.Get(ref.ID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gin-gonic/gin v1.9.0
github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c
github.com/konveyor/tackle2-addon v0.1.2-0.20230510185644-c600b133619a
github.com/konveyor/tackle2-hub v0.2.1-0.20230703140704-8e7520555b96
github.com/konveyor/tackle2-hub v0.2.2-0.20230716141827-62f426b6d1a6
github.com/onsi/gomega v1.27.6
go.lsp.dev/uri v0.3.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c h1:DbOZO3cNm
github.com/konveyor/analyzer-lsp v0.0.0-20230712145100-60dc2048444c/go.mod h1:+k6UreVv8ztI29/RyQN8/71AAmB0aWwQoWwZd3yR8sc=
github.com/konveyor/tackle2-addon v0.1.2-0.20230510185644-c600b133619a h1:ujBSPC+MzWyF5GRALc7KXd96wJZEuN/ao1meUfvBT2M=
github.com/konveyor/tackle2-addon v0.1.2-0.20230510185644-c600b133619a/go.mod h1:2poGMxU2vxmz7+FppLvSliMrk0mAtbDHp+LeZ/p2/Q8=
github.com/konveyor/tackle2-hub v0.2.1-0.20230703140704-8e7520555b96 h1:ad9WGM95eq1xcLdxQzVv3Kk71s5322iXv3Cj7vJffD8=
github.com/konveyor/tackle2-hub v0.2.1-0.20230703140704-8e7520555b96/go.mod h1:UR7IJ1Qa9RgcdsO81yLWjTB6h7Qz1Y2bypu6YU2LFg8=
github.com/konveyor/tackle2-hub v0.2.2-0.20230716141827-62f426b6d1a6 h1:A4vgEkHF1jJnTpL2uU8sDPJ+iQQAYl16QXgSILx3gTQ=
github.com/konveyor/tackle2-hub v0.2.2-0.20230716141827-62f426b6d1a6/go.mod h1:UR7IJ1Qa9RgcdsO81yLWjTB6h7Qz1Y2bypu6YU2LFg8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down

0 comments on commit eb5eea7

Please sign in to comment.