Less verbose logging in Golang Cataloger (#904)

* Less verbose logging in Golang Cataloger

Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com>

* debug for known gray errors

Signed-off-by: Jonas Galvão Xavier <jonas.agx@gmail.com>

* only show warnings when a binary is not a go executable

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

Co-authored-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Jonas Xavier 2022-03-22 10:19:18 -07:00 committed by GitHub
parent cffcaf5984
commit c0b547bdb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,17 +24,27 @@ func scanFile(reader unionReader, filename string) ([]*debug.BuildInfo, []string
// with more than one binary // with more than one binary
readers, err := getReaders(reader) readers, err := getReaders(reader)
if err != nil { if err != nil {
log.Warnf("golang cataloger: opening binary: %v", err) log.Warnf("golang cataloger: failed to open a binary: %v", err)
return nil, nil return nil, nil
} }
var builds []*debug.BuildInfo var builds []*debug.BuildInfo
for _, r := range readers { for _, r := range readers {
bi, err := buildinfo.Read(r) bi, err := buildinfo.Read(r)
// note: the stdlib does not export the error we need to check for
if err != nil { if err != nil {
log.Warnf("golang cataloger: scanning file %s: %v", filename, err) if err.Error() == "not a Go executable" {
// since the cataloger can only select executables and not distinguish if they are a go-compiled
// binary, we should not show warnings/logs in this case.
return nil, nil
}
// in this case we could not read the or parse the file, but not explicitly because it is not a
// go-compiled binary (though it still might be).
log.Warnf("golang cataloger: failed to read buildinfo (file=%q): %v", filename, err)
return nil, nil return nil, nil
} }
builds = append(builds, bi) builds = append(builds, bi)
} }