Return error if any linter fails to run (#2471)

This commit is contained in:
Simon Sawert 2022-01-15 18:55:36 +01:00 committed by GitHub
parent 95b9b23464
commit b5d8e6982c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"runtime/debug" "runtime/debug"
"strings" "strings"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors" "github.com/pkg/errors"
gopackages "golang.org/x/tools/go/packages" gopackages "golang.org/x/tools/go/packages"
@ -192,20 +193,26 @@ func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *lint
sw := timeutils.NewStopwatch("linters", r.Log) sw := timeutils.NewStopwatch("linters", r.Log)
defer sw.Print() defer sw.Print()
var issues []result.Issue var (
lintErrors *multierror.Error
issues []result.Issue
)
for _, lc := range linters { for _, lc := range linters {
lc := lc lc := lc
sw.TrackStage(lc.Name(), func() { sw.TrackStage(lc.Name(), func() {
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc) linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
if err != nil { if err != nil {
lintErrors = multierror.Append(lintErrors, fmt.Errorf("can't run linter %s: %w", lc.Linter.Name(), err))
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err) r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
return return
} }
issues = append(issues, linterIssues...) issues = append(issues, linterIssues...)
}) })
} }
return r.processLintResults(issues), nil return r.processLintResults(issues), lintErrors.ErrorOrNil()
} }
func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue { func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue {