mirror of
https://github.com/securego/gosec.git
synced 2024-12-25 20:15:54 +00:00
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.
This commit is contained in:
parent
bc21a39c66
commit
d3f0a08f0d
2 changed files with 8 additions and 6 deletions
|
@ -16,6 +16,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/importer"
|
"go/importer"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
|
@ -123,10 +124,9 @@ func (gas *Analyzer) process(filename string, source interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := types.Config{Importer: importer.Default()}
|
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 {
|
if err != nil {
|
||||||
gas.logger.Println("failed to check imports")
|
return fmt.Errorf(`Error during type checking: "%s"`, err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gas.context.Imports = NewImportInfo()
|
gas.context.Imports = NewImportInfo()
|
||||||
|
|
8
main.go
8
main.go
|
@ -176,7 +176,7 @@ func main() {
|
||||||
// Ensure at least one file was specified
|
// Ensure at least one file was specified
|
||||||
if flag.NArg() == 0 {
|
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()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -195,9 +195,11 @@ func main() {
|
||||||
toAnalyze := getFilesToAnalyze(flag.Args(), excluded)
|
toAnalyze := getFilesToAnalyze(flag.Args(), excluded)
|
||||||
|
|
||||||
for _, file := range toAnalyze {
|
for _, file := range toAnalyze {
|
||||||
logger.Printf("scanning \"%s\"\n", file)
|
logger.Printf(`Processing "%s"...`, file)
|
||||||
if err := analyzer.Process(file); err != nil {
|
if err := analyzer.Process(file); err != nil {
|
||||||
logger.Fatal(err)
|
logger.Printf(`Failed to process: "%s"`, file)
|
||||||
|
logger.Println(err)
|
||||||
|
logger.Fatalf(`Halting execution.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue