}
wg.Wait()
- // if there are errors, return the first one for deterministic results
+ // If there are errors, return the first one for deterministic results.
+ var first error
for _, err := range errors {
if err != nil {
- return nil, err
+ first = err
+ // If we have an error, some files may be nil.
+ // Remove them. (The go/parser always returns
+ // a possibly partial AST even in the presence
+ // of errors, except if the file doesn't exist
+ // in the first place, in which case it cannot
+ // matter.)
+ i := 0
+ for _, f := range files {
+ if f != nil {
+ files[i] = f
+ i++
+ }
+ }
+ files = files[:i]
+ break
}
}
- return files, nil
+ return files, first
}
func parseDir(dir string) ([]*ast.File, error) {
files, err := getPkgFiles(flag.Args())
if err != nil {
report(err)
- os.Exit(2)
+ // ok to continue (files may be empty, but not nil)
}
checkPkgFiles(files)