From c0b547bdb239f00ef43b7f69a61813b710d0b221 Mon Sep 17 00:00:00 2001 From: Jonas Xavier Date: Tue, 22 Mar 2022 10:19:18 -0700 Subject: [PATCH] Less verbose logging in Golang Cataloger (#904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Less verbose logging in Golang Cataloger Signed-off-by: Jonas Galvão Xavier * debug for known gray errors Signed-off-by: Jonas Galvão Xavier * only show warnings when a binary is not a go executable Signed-off-by: Alex Goodman Co-authored-by: Alex Goodman --- syft/pkg/cataloger/golang/scan_bin.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/syft/pkg/cataloger/golang/scan_bin.go b/syft/pkg/cataloger/golang/scan_bin.go index 847191efcba..5663492d638 100644 --- a/syft/pkg/cataloger/golang/scan_bin.go +++ b/syft/pkg/cataloger/golang/scan_bin.go @@ -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) }