From 25ee1f3e79d2f975cc79be4a78297399a4853ccb Mon Sep 17 00:00:00 2001 From: Xavi Garcia Date: Mon, 16 Mar 2026 10:23:21 +0100 Subject: [PATCH] Return cli List error closer to where was returned When looking for a different issue I found this code that confused me. In case List returns an error we're still trying to iterate the returned list (that should be empty, we cannot guarantee) This PR returns the error earlier and avoids accessing the list, that in future implementations of List could be returning nil and make this panic. Signed-off-by: Xavi Garcia --- internal/cmd/cli/apply/apply.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/cmd/cli/apply/apply.go b/internal/cmd/cli/apply/apply.go index ef794a144b..4a9a491783 100644 --- a/internal/cmd/cli/apply/apply.go +++ b/internal/cmd/cli/apply/apply.go @@ -354,7 +354,9 @@ func pruneBundlesNotFoundInRepo( ) error { filter := labels.SelectorFromSet(labels.Set{fleet.RepoLabel: repoName}) bundleList := &fleet.BundleList{} - err := c.List(ctx, bundleList, &client.ListOptions{LabelSelector: filter, Namespace: ns}) + if err := c.List(ctx, bundleList, &client.ListOptions{LabelSelector: filter, Namespace: ns}); err != nil { + return err + } for _, bundle := range bundleList.Items { if _, ok := gitRepoBundlesMap[bundle.Name]; !ok { @@ -404,13 +406,12 @@ func pruneBundlesNotFoundInRepo( } } } - err = c.Delete(ctx, &bundle) - if err != nil { + if err := c.Delete(ctx, &bundle); err != nil { return err } } } - return err + return nil } // newBundle reads bundle data from a source and returns a bundle with the