Skip to content

Commit

Permalink
Report a failure and exit if type checking fails
Browse files Browse the repository at this point in the history
Type checking failures were previously not reported and the file was
silently ignored. This change will report the error and halt further
processing.
  • Loading branch information
gcmurphy committed Jan 13, 2017
1 parent bc21a39 commit d3f0a08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package core

import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
Expand Down Expand Up @@ -123,10 +124,9 @@ func (gas *Analyzer) process(filename string, source interface{}) error {
}

conf := types.Config{Importer: importer.Default()}
gas.context.Pkg, _ = conf.Check("pkg", gas.context.FileSet, []*ast.File{root}, gas.context.Info)
gas.context.Pkg, err = conf.Check("pkg", gas.context.FileSet, []*ast.File{root}, gas.context.Info)
if err != nil {
gas.logger.Println("failed to check imports")
return err
return fmt.Errorf(`Error during type checking: "%s"`, err)
}

gas.context.Imports = NewImportInfo()
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func main() {
// Ensure at least one file was specified
if flag.NArg() == 0 {

fmt.Fprintf(os.Stderr, "\nerror: FILE [FILE...] or './...' expected\n")
fmt.Fprintf(os.Stderr, "\nError: FILE [FILE...] or './...' expected\n")
flag.Usage()
os.Exit(1)
}
Expand All @@ -195,9 +195,11 @@ func main() {
toAnalyze := getFilesToAnalyze(flag.Args(), excluded)

for _, file := range toAnalyze {
logger.Printf("scanning \"%s\"\n", file)
logger.Printf(`Processing "%s"...`, file)
if err := analyzer.Process(file); err != nil {
logger.Fatal(err)
logger.Printf(`Failed to process: "%s"`, file)
logger.Println(err)
logger.Fatalf(`Halting execution.`)
}
}

Expand Down

0 comments on commit d3f0a08

Please sign in to comment.