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.
This commit is contained in:
Denis Isaev 2019-09-10 18:48:41 +03:00
parent f1c1dbfab4
commit 4495f893b9
No known key found for this signature in database
GPG Key ID: A36A0EC8E27A1A01
2 changed files with 17 additions and 3 deletions

View File

@ -5,11 +5,13 @@
fast_build: FORCE
go build -o golangci-lint ./cmd/golangci-lint
build_race: FORCE
go build -race -o golangci-lint ./cmd/golangci-lint
build: golangci-lint
clean:
rm -f golangci-lint test/path
rm -rf tools
.PHONY: fast_build build clean
.PHONY: fast_build build build_race clean
# Test

View File

@ -19,6 +19,7 @@ import (
"os"
"reflect"
"runtime"
"runtime/debug"
"runtime/pprof"
"runtime/trace"
"sort"
@ -285,11 +286,17 @@ func (act *action) String() string {
func execAll(actions []*action) {
sequential := dbg('p')
var wg sync.WaitGroup
for _, act := range actions {
panics := make([]interface{}, len(actions))
for i, act := range actions {
wg.Add(1)
work := func(act *action) {
act.exec()
defer func() {
wg.Done()
if p := recover(); p != nil {
panics[i] = fmt.Errorf("%s: %s", p, debug.Stack())
}
}()
act.exec()
}
if sequential {
work(act)
@ -298,6 +305,11 @@ func execAll(actions []*action) {
}
}
wg.Wait()
for _, p := range panics {
if p != nil {
panic(p)
}
}
}
func (act *action) exec() { act.once.Do(act.execOnce) }