Skip to content

Commit 16f8c66

Browse files
committed
fix: correctly handle empty component references
1 parent a620ebf commit 16f8c66

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/ocm-cli/component_getter.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,18 @@ func (g *ComponentGetter) GetReferencedComponentVersionsRecursive(ctx context.Co
117117

118118
// First, try to get the reference directly from the parent component version
119119
refs, err := g.GetReferencedComponentVersions(ctx, parentCV, refName)
120-
if err == nil {
120+
if err != nil {
121+
return nil, fmt.Errorf("error getting referenced component versions for %s: %w", refName, err)
122+
}
123+
124+
if len(refs) > 0 {
121125
return refs, nil
122126
}
123127

124128
// If not found, search recursively in all component references
125129
for _, componentRef := range parentCV.Component.ComponentReferences {
126130
subCVs, err := g.GetReferencedComponentVersions(ctx, parentCV, componentRef.Name)
127-
if err != nil {
131+
if err != nil || len(subCVs) == 0 {
128132
continue
129133
}
130134
for _, subCV := range subCVs {
@@ -151,7 +155,7 @@ func (g *ComponentGetter) GetComponentVersionsForResourceRecursive(ctx context.C
151155
// If not found, search recursively in all component references
152156
for _, componentRef := range parentCV.Component.ComponentReferences {
153157
subCVs, err := g.GetReferencedComponentVersions(ctx, parentCV, componentRef.Name)
154-
if err != nil {
158+
if err != nil || len(subCVs) == 0 {
155159
continue
156160
}
157161
for _, subCV := range subCVs {

0 commit comments

Comments
 (0)