From 0139d3484144f0812694c79d4c12f21f4b7aef9d Mon Sep 17 00:00:00 2001 From: Payal Godhani Date: Mon, 8 Sep 2025 16:40:50 -0700 Subject: [PATCH 1/2] add detailed logging and error handling for chart download and cache operations -e Signed-off-by: Payal Godhani --- pkg/downloader/chart_downloader.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 00c8c56e8..7ede44c51 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -246,22 +246,31 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena if len(digest) == 0 || err != nil { slog.Debug("attempting to download chart", "ref", ref, "version", version) if err != nil && !os.IsNotExist(err) { + slog.Error("failed to access chart cache", "error", err, "ref", ref, "version", version) return "", nil, err } // Get file not in the cache data, gerr := g.Get(u.String(), c.Options...) if gerr != nil { + slog.Error("failed to download chart from remote", "error", gerr, "url", u.String(), "ref", ref, "version", version) return "", nil, gerr } // Generate the digest if len(digest) == 0 { - digest32 = sha256.Sum256(data.Bytes()) + // Defensive: check data.Bytes() is not nil/empty + bytes := data.Bytes() + if len(bytes) == 0 { + slog.Error("downloaded chart data is empty", "url", u.String(), "ref", ref, "version", version) + return "", nil, errors.New("downloaded chart data is empty") + } + digest32 = sha256.Sum256(bytes) } pth, err = c.Cache.Put(digest32, data, CacheChart) if err != nil { + slog.Error("failed to put chart in cache", "error", err, "cache_id", hex.EncodeToString(digest32[:])) return "", nil, err } slog.Debug("put downloaded chart in cache", "id", hex.EncodeToString(digest32[:])) From 5fcc2157da183c392096340e9d3b98195e07ff53 Mon Sep 17 00:00:00 2001 From: Payal Godhani Date: Tue, 9 Sep 2025 10:41:01 -0700 Subject: [PATCH 2/2] Addressing the feedback and changing the log to debug level -e Signed-off-by: Payal Godhani --- pkg/downloader/chart_downloader.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 7ede44c51..9ff6fe7bf 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -246,14 +246,14 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena if len(digest) == 0 || err != nil { slog.Debug("attempting to download chart", "ref", ref, "version", version) if err != nil && !os.IsNotExist(err) { - slog.Error("failed to access chart cache", "error", err, "ref", ref, "version", version) + slog.Debug("failed to access chart cache", "error", err, "ref", ref, "version", version) return "", nil, err } // Get file not in the cache data, gerr := g.Get(u.String(), c.Options...) if gerr != nil { - slog.Error("failed to download chart from remote", "error", gerr, "url", u.String(), "ref", ref, "version", version) + slog.Debug("failed to download chart from remote", "error", gerr, "url", u.String(), "ref", ref, "version", version) return "", nil, gerr } @@ -262,7 +262,7 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena // Defensive: check data.Bytes() is not nil/empty bytes := data.Bytes() if len(bytes) == 0 { - slog.Error("downloaded chart data is empty", "url", u.String(), "ref", ref, "version", version) + slog.Debug("downloaded chart data is empty", "url", u.String(), "ref", ref, "version", version) return "", nil, errors.New("downloaded chart data is empty") } digest32 = sha256.Sum256(bytes) @@ -270,7 +270,7 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena pth, err = c.Cache.Put(digest32, data, CacheChart) if err != nil { - slog.Error("failed to put chart in cache", "error", err, "cache_id", hex.EncodeToString(digest32[:])) + slog.Debug("failed to put chart in cache", "error", err, "cache_id", hex.EncodeToString(digest32[:])) return "", nil, err } slog.Debug("put downloaded chart in cache", "id", hex.EncodeToString(digest32[:]))