Skip to content

Commit

Permalink
🐛 Report ruleErr outside of builder stream. (#113)
Browse files Browse the repository at this point in the history
To support succeeded with errors, the RuleError cannot be returned in
the builder stream because it is interpreted as a streaming error by the
multi-part form send.

related: konveyor/tackle2-hub#729

closes #114

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Jul 17, 2024
1 parent a35f376 commit 19873f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
15 changes: 8 additions & 7 deletions builder/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ type Issues struct {
Path string
}

// RuleError returns the rule error.
func (b *Issues) RuleError() (r *RuleError) {
return &b.ruleErr
}

// Reader returns a reader.
func (b *Issues) Reader() (r io.Reader) {
r, w := io.Pipe()
Expand Down Expand Up @@ -93,13 +98,6 @@ func (b *Issues) Write(writer io.Writer) (err error) {
}
}
}
if err != nil {
return
}
if b.ruleErr.NotEmpty() {
err = &b.ruleErr
return
}
return
}

Expand Down Expand Up @@ -178,6 +176,9 @@ func (e *RuleError) NotEmpty() (b bool) {
}

func (e *RuleError) Report() {
if len(e.items) == 0 {
return
}
var errors []api.TaskError
for ruleid, err := range e.items {
errors = append(
Expand Down
18 changes: 7 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"os"
"path"
"time"
Expand Down Expand Up @@ -130,17 +129,14 @@ func main() {
binding.MIMEYAML,
issues.Reader(),
deps.Reader())
if err == nil {
addon.Activity("Analysis reported. duration: %s", time.Since(mark))
} else {
ruleErr := &RuleError{}
if errors.As(err, &ruleErr) {
ruleErr.Report()
err = nil
} else {
return
}
if err != nil {
return
}
addon.Activity("Analysis reported. duration: %s", time.Since(mark))
//
// RuleError
ruleErr := issues.RuleError()
ruleErr.Report()
//
// Facts
facts := addon.Application.Facts(application.ID)
Expand Down

0 comments on commit 19873f4

Please sign in to comment.