Skip to content

Commit d3f0a08

Browse files
committed
Report a failure and exit if type checking fails
Type checking failures were previously not reported and the file was silently ignored. This change will report the error and halt further processing.
1 parent bc21a39 commit d3f0a08

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/analyzer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package core
1717

1818
import (
19+
"fmt"
1920
"go/ast"
2021
"go/importer"
2122
"go/parser"
@@ -123,10 +124,9 @@ func (gas *Analyzer) process(filename string, source interface{}) error {
123124
}
124125

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

132132
gas.context.Imports = NewImportInfo()

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func main() {
176176
// Ensure at least one file was specified
177177
if flag.NArg() == 0 {
178178

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

197197
for _, file := range toAnalyze {
198-
logger.Printf("scanning \"%s\"\n", file)
198+
logger.Printf(`Processing "%s"...`, file)
199199
if err := analyzer.Process(file); err != nil {
200-
logger.Fatal(err)
200+
logger.Printf(`Failed to process: "%s"`, file)
201+
logger.Println(err)
202+
logger.Fatalf(`Halting execution.`)
201203
}
202204
}
203205

0 commit comments

Comments
 (0)