From 05ab8137453b1c2ed6892f3291da8e871edb168f Mon Sep 17 00:00:00 2001 From: antyagi Date: Sat, 7 Mar 2026 01:15:27 +0530 Subject: [PATCH] feat: handling error in coalesce Signed-off-by: antyagi --- pkg/chart/common/util/coalesce.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/chart/common/util/coalesce.go b/pkg/chart/common/util/coalesce.go index d8f10a7e8..8bafcd18e 100644 --- a/pkg/chart/common/util/coalesce.go +++ b/pkg/chart/common/util/coalesce.go @@ -121,7 +121,10 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi dvmap := dv.(map[string]any) subPrefix := concatPrefix(prefix, ch.Name()) // Get globals out of dest and merge them into dvmap. - coalesceGlobals(printf, dvmap, dest, subPrefix, merge) + err = coalesceGlobals(printf, dvmap, dest, subPrefix, merge) + if err != nil { + return dest, err + } // Now coalesce the rest of the values. var err error dest[sub.Name()], err = coalesce(printf, subchart, dvmap, subPrefix, merge) @@ -136,21 +139,21 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefi // coalesceGlobals copies the globals out of src and merges them into dest. // // For convenience, returns dest. -func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) { +func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) error { var dg, sg map[string]any if destglob, ok := dest[common.GlobalKey]; !ok { dg = make(map[string]any) } else if dg, ok = destglob.(map[string]any); !ok { printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey) - return + return nil } if srcglob, ok := src[common.GlobalKey]; !ok { sg = make(map[string]any) } else if sg, ok = srcglob.(map[string]any); !ok { printf("warning: skipping globals because source %s is not a table.", common.GlobalKey) - return + return nil } // EXPERIMENTAL: In the past, we have disallowed globals to test tables. This @@ -159,8 +162,15 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ // tables in globals. for key, val := range sg { if istable(val) { - valCopy, _ := copystructure.Copy(val) - vv := valCopy.(map[string]interface{}) + valCopy, err := copystructure.Copy(val) + if err != nil { + return err + } + vv, ok := valCopy.(map[string]any) + if !ok { + printf("warning: unable to convert globals copy to Helm values type") + continue + } if destv, ok := dg[key]; !ok { // Here there is no merge. We're just adding. dg[key] = vv @@ -187,6 +197,7 @@ func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ } } dest[common.GlobalKey] = dg + return nil }