From 61874cf532eb98a5b26dc57dcbb061f5917760a1 Mon Sep 17 00:00:00 2001 From: Cloud-Architect-Emma Date: Tue, 30 Jun 2026 00:46:39 +0100 Subject: [PATCH] fix: return nil IndexFile on error paths in LoadIndexFileForEntries Return nil instead of partially initialized IndexFile on: - empty file (ErrEmptyIndexYaml) - unmarshal failure - missing API version (ErrNoAPIVersion) Matches LoadIndexFile contract and prevents callers from accidentally proceeding with an invalid index. Signed-off-by: Cloud-Architect-Emma --- pkg/repo/v1/index.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/repo/v1/index.go b/pkg/repo/v1/index.go index 470e28514..19c357d5d 100644 --- a/pkg/repo/v1/index.go +++ b/pkg/repo/v1/index.go @@ -129,10 +129,10 @@ func LoadIndexFileForEntries(path string, names []string) (*IndexFile, error) { } i := &IndexFile{} if len(b) == 0 { - return i, ErrEmptyIndexYaml + return nil, ErrEmptyIndexYaml } if err := jsonOrYamlUnmarshal(b, i); err != nil { - return i, err + return nil, err } // Build a new map containing only the requested entries to reduce heap usage. retained := make(map[string]ChartVersions, len(names)) @@ -165,7 +165,7 @@ func LoadIndexFileForEntries(path string, names []string) (*IndexFile, error) { } i.SortEntries() if i.APIVersion == "" { - return i, ErrNoAPIVersion + return nil, ErrNoAPIVersion } return i, nil } @@ -450,7 +450,7 @@ func loadIndex(data []byte, source string) (*IndexFile, error) { } i.SortEntries() if i.APIVersion == "" { - return i, ErrNoAPIVersion + return nil, ErrNoAPIVersion } return i, nil }