From cb1c7c59f0500157e75a2500d7d9955a9eeed8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Comb=C3=BCchen?= Date: Mon, 5 Feb 2024 14:32:03 +0100 Subject: [PATCH] fix: log errors during SPDX snyk enrich (#52) --- lib/snyk/enrich_spdx.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/snyk/enrich_spdx.go b/lib/snyk/enrich_spdx.go index 22c0e6d..bf53e59 100644 --- a/lib/snyk/enrich_spdx.go +++ b/lib/snyk/enrich_spdx.go @@ -69,17 +69,26 @@ func enrichSPDX(bom *spdx.Document, logger zerolog.Logger) *spdx.Document { } resp, err := GetPackageVulnerabilities(purl, auth, orgID) + if err != nil { + logger.Err(err). + Str("purl", purl.ToString()). + Msg("Failed to fetch vulnerabilities for package.") + return + } + + packageData := resp.Body + var packageDoc issues.IssuesWithPurlsResponse + if err := json.Unmarshal(packageData, &packageDoc); err != nil { + logger.Err(err). + Str("status", resp.Status()). + Msg("Failed to decode Snyk vulnerability response.") + return + } - if err == nil { - packageData := resp.Body - var packageDoc issues.IssuesWithPurlsResponse - if err := json.Unmarshal(packageData, &packageDoc); err == nil { - if packageDoc.Data != nil { - mutex.Lock() - vulnerabilities[pkg] = *packageDoc.Data - mutex.Unlock() - } - } + if packageDoc.Data != nil { + mutex.Lock() + vulnerabilities[pkg] = *packageDoc.Data + mutex.Unlock() } }(pkg, i) }