Skip to content

Commit 4495f89

Browse files
committed
Log go/analysis panics, don't crash
go/analysis panics were propagated to main and crashed golangci-lint. Just log them, as with other linters. Found in #608.
1 parent f1c1dbf commit 4495f89

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
fast_build: FORCE
77
go build -o golangci-lint ./cmd/golangci-lint
8+
build_race: FORCE
9+
go build -race -o golangci-lint ./cmd/golangci-lint
810
build: golangci-lint
911
clean:
1012
rm -f golangci-lint test/path
1113
rm -rf tools
12-
.PHONY: fast_build build clean
14+
.PHONY: fast_build build build_race clean
1315

1416
# Test
1517

pkg/golinters/goanalysis/checker/checker.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"os"
2020
"reflect"
2121
"runtime"
22+
"runtime/debug"
2223
"runtime/pprof"
2324
"runtime/trace"
2425
"sort"
@@ -285,11 +286,17 @@ func (act *action) String() string {
285286
func execAll(actions []*action) {
286287
sequential := dbg('p')
287288
var wg sync.WaitGroup
288-
for _, act := range actions {
289+
panics := make([]interface{}, len(actions))
290+
for i, act := range actions {
289291
wg.Add(1)
290292
work := func(act *action) {
293+
defer func() {
294+
wg.Done()
295+
if p := recover(); p != nil {
296+
panics[i] = fmt.Errorf("%s: %s", p, debug.Stack())
297+
}
298+
}()
291299
act.exec()
292-
wg.Done()
293300
}
294301
if sequential {
295302
work(act)
@@ -298,6 +305,11 @@ func execAll(actions []*action) {
298305
}
299306
}
300307
wg.Wait()
308+
for _, p := range panics {
309+
if p != nil {
310+
panic(p)
311+
}
312+
}
301313
}
302314

303315
func (act *action) exec() { act.once.Do(act.execOnce) }

0 commit comments

Comments
 (0)