Skip to content

Commit 9464bf5

Browse files
committed
Return error if any linter fails to run
If a linter fails to run, store its name and use that to create a list of all linters that failed to run. This will make `golangci-lint` exit with a non-zero exit code if one or more linters fails but still ensure all linters are run before exiting.
1 parent e443887 commit 9464bf5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/lint/runner.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,34 @@ func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *lint
192192
sw := timeutils.NewStopwatch("linters", r.Log)
193193
defer sw.Print()
194194

195-
var issues []result.Issue
195+
var (
196+
linterErr error
197+
failedLinters []string
198+
issues []result.Issue
199+
)
200+
196201
for _, lc := range linters {
197202
lc := lc
198203
sw.TrackStage(lc.Name(), func() {
199204
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
200205
if err != nil {
206+
failedLinters = append(failedLinters, lc.Linter.Name())
201207
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
208+
202209
return
203210
}
204211
issues = append(issues, linterIssues...)
205212
})
206213
}
207214

208-
return r.processLintResults(issues), nil
215+
if len(failedLinters) > 0 {
216+
linterErr = fmt.Errorf(
217+
"one or more linters failed to run: %s",
218+
strings.Join(failedLinters, ", "),
219+
)
220+
}
221+
222+
return r.processLintResults(issues), linterErr
209223
}
210224

211225
func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue {

0 commit comments

Comments
 (0)