From 1401107138fde3ab21769a848cb4c5e02d274313 Mon Sep 17 00:00:00 2001 From: idhyt Date: Mon, 26 Oct 2026 23:05:27 +0800 Subject: [PATCH] fix(go-module-cataloger): use correct error variable in package load loop (#4983) In the loop over `rootPkgs`, the error appended to `unknownErr` was incorrectly using the outer `err` (from `packages.Load`) instead of the individual package error `e`. This could cause: - nil or stale error values to be recorded when package-specific errors existed. - Loss of detailed per-package error information in the final error report. Changed `unknown.Append(..., err)` to `unknown.Append(..., e)` to properly capture each package's load error. Signed-off-by: idhyt --- syft/pkg/cataloger/golang/parse_go_mod.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syft/pkg/cataloger/golang/parse_go_mod.go b/syft/pkg/cataloger/golang/parse_go_mod.go index c4a727987..7748759aa 100644 --- a/syft/pkg/cataloger/golang/parse_go_mod.go +++ b/syft/pkg/cataloger/golang/parse_go_mod.go @@ -137,9 +137,9 @@ func (c *goModCataloger) loadPackages(modDir string, loc file.Location) (pkgs ma for _, p := range rootPkgs { if len(p.Errors) > 0 { // Log errors but continue processing - for _, e := range p.Errors { - log.Debugf("package load error for %s: %v", p.PkgPath, e) - unknownErr = unknown.Append(unknownErr, loc, err) + for _, pe := range p.Errors { + log.Debugf("package load error for %s: %v", p.PkgPath, pe) + unknownErr = unknown.Append(unknownErr, loc, pe) } } }