From 19873f4299c24a2e755b78c6a65b0712d03a5971 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Wed, 17 Jul 2024 07:46:58 -0500 Subject: [PATCH] :bug: Report ruleErr outside of builder stream. (#113) 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: https://github.com/konveyor/tackle2-hub/pull/729 closes #114 --------- Signed-off-by: Jeff Ortel --- builder/issue.go | 15 ++++++++------- cmd/main.go | 18 +++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/builder/issue.go b/builder/issue.go index 078ca67..dc909c6 100644 --- a/builder/issue.go +++ b/builder/issue.go @@ -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() @@ -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 } @@ -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( diff --git a/cmd/main.go b/cmd/main.go index 7c36175..438d842 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,7 +1,6 @@ package main import ( - "errors" "os" "path" "time" @@ -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)