From f6605a381731e09f312e9b0a124e776b980a0376 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Thu, 27 Feb 2025 16:52:50 -0500 Subject: [PATCH] suppress file already closed errors (#3695) Signed-off-by: Alex Goodman --- internal/err_helper.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/err_helper.go b/internal/err_helper.go index d9625c17a..4ced7c1f8 100644 --- a/internal/err_helper.go +++ b/internal/err_helper.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "io/fs" "os" "github.com/anchore/syft/internal/log" @@ -12,6 +13,10 @@ import ( // CloseAndLogError closes the given io.Closer and reports any errors found as a warning in the log func CloseAndLogError(closer io.Closer, location string) { if err := closer.Close(); err != nil { + // suppress "file already closed" log messages + if errors.Is(err, fs.ErrClosed) { + return + } log.Debugf("unable to close file for location=%q: %+v", location, err) } }