Skip to content

Commit

Permalink
Less verbose logging in Golang Cataloger (#904)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jonasagx and wagoodman authored Mar 22, 2022
1 parent cffcaf5 commit c0b547b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions syft/pkg/cataloger/golang/scan_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,27 @@ func scanFile(reader unionReader, filename string) ([]*debug.BuildInfo, []string
// with more than one binary
readers, err := getReaders(reader)
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
}

var builds []*debug.BuildInfo
for _, r := range readers {
bi, err := buildinfo.Read(r)

// note: the stdlib does not export the error we need to check for
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
}

builds = append(builds, bi)
}

Expand Down

0 comments on commit c0b547b

Please sign in to comment.