fix config validation

This commit is contained in:
golangci 2018-05-19 13:07:55 +03:00
parent 5e3eae0cf1
commit 328b32ac61
4 changed files with 12 additions and 8 deletions

2
Gopkg.lock generated
View File

@ -91,7 +91,7 @@
"unused",
"version"
]
revision = "d26f272c11fdcbab5d498e7fb88587ac179f3235"
revision = "e37cd5dbe6dac91e427e242d7fb61cc92201c8bf"
[[projects]]
branch = "master"

View File

@ -323,6 +323,8 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
viper.SetConfigFile(configFile)
}
commandLineConfig := *e.cfg // make copy
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
return
@ -334,22 +336,22 @@ func (e *Executor) parseConfig(cmd *cobra.Command) {
log.Fatalf("Can't unmarshal config by viper: %s", err)
}
if err := e.validateConfig(); err != nil {
if err := e.validateConfig(&commandLineConfig); err != nil {
log.Fatal(err)
}
}
func (e *Executor) validateConfig() error {
func (e *Executor) validateConfig(commandLineConfig *config.Config) error {
c := e.cfg
if len(c.Run.Args) != 0 {
return errors.New("option run.args in config aren't supported now")
return errors.New("option run.args in config isn't supported now")
}
if c.Run.CPUProfilePath != "" {
if commandLineConfig.Run.CPUProfilePath == "" && c.Run.CPUProfilePath != "" {
return errors.New("option run.cpuprofilepath in config isn't allowed")
}
if c.Run.IsVerbose {
if !commandLineConfig.Run.IsVerbose && c.Run.IsVerbose {
return errors.New("can't set run.verbose option with config: only on command-line")
}

View File

@ -111,7 +111,7 @@ func (r SimpleRunner) runGo(ctx context.Context, linters []Linter, lintCtx *goli
finishedN := 0
for res := range lintResultsCh {
if res.err != nil {
logrus.Warnf("Can't run linter %s: %s", res.linter.Name(), res.err)
logrus.Infof("Can't run linter %s: %s", res.linter.Name(), res.err)
continue
}

View File

@ -18,6 +18,7 @@ import (
"go/types"
"path/filepath"
"runtime"
"runtime/debug"
"sort"
"strings"
"sync"
@ -423,7 +424,8 @@ func (l *Linter) Lint(lprog *loader.Program, conf *loader.Config, ssaprog *ssa.P
go func(i int, j *Job) {
defer func() {
if err := recover(); err != nil {
crashesMap.Store(i, err)
perr := fmt.Errorf("panic: %s, stack: %s", err, debug.Stack())
crashesMap.Store(i, perr)
}
}()
defer wg.Done()