From c3091bd61224dc99030ef6f0298cdc22738de476 Mon Sep 17 00:00:00 2001 From: Ogulcan Aydogan Date: Tue, 26 May 2026 12:18:42 +0100 Subject: [PATCH] Improve error message for invalid Helm chart repository URLs Wrap the errors from CacheIndex() and LoadFromPath() in reconcileSource with a helm-CLI-style message that includes the configured repository URL. When the index cannot be fetched or fails to parse (e.g. server returns HTML instead of YAML), the user now sees: looks like "https://example.com" is not a valid chart repository or cannot be reached: instead of the cryptic YAML parse error or generic fetch failure. Fixes #654 Signed-off-by: Ogulcan Aydogan --- internal/controller/helmrepository_controller.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/controller/helmrepository_controller.go b/internal/controller/helmrepository_controller.go index 0fd7eedc2..de042da6e 100644 --- a/internal/controller/helmrepository_controller.go +++ b/internal/controller/helmrepository_controller.go @@ -450,7 +450,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc // Fetch the repository index from remote. if err := newChartRepo.CacheIndex(); err != nil { e := serror.NewGeneric( - fmt.Errorf("failed to fetch Helm repository index: %w", err), + invalidChartRepoError(obj.Spec.URL, err), meta.FailedReason, ) conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e) @@ -476,7 +476,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc // Load the cached repository index to ensure it passes validation. if err := chartRepo.LoadFromPath(); err != nil { e := serror.NewGeneric( - fmt.Errorf("failed to load Helm repository from index YAML: %w", err), + invalidChartRepoError(obj.Spec.URL, err), sourcev1.IndexationFailedReason, ) conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e) @@ -723,3 +723,10 @@ func (r *HelmRepositoryReconciler) migrationToStatic(ctx context.Context, sp *pa return ctrl.Result{}, nil } + +// invalidChartRepoError formats an error indicating the given URL is not +// a valid Helm chart repository or cannot be reached, mirroring the +// `helm repo add` CLI output. +func invalidChartRepoError(repoURL string, err error) error { + return fmt.Errorf("looks like %q is not a valid chart repository or cannot be reached: %w", repoURL, err) +}