From 9fb2a86f876fc86b9dd290f1aa875f4cb145a59a Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Thu, 15 Jan 2026 16:42:18 +0100 Subject: [PATCH 1/2] fix(lookup): initialize map to prevent nil map assignment panic Fix panic "assignment to entry in nil map" when lookup function processes resources with empty or malformed metadata. The issue occurred because `res` was declared as nil map and could remain nil if yaml.Unmarshal didn't populate it, causing panic at `res["spec"] = unmarshalledData`. Fixes #95 Co-Authored-By: Claude Signed-off-by: Andrei Kvapil --- pkg/engine/engine.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 388bedb..d5a40e4 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -563,11 +563,18 @@ func readUnexportedField(field reflect.Value) any { // builds resource with metadata, spec and stringSpec fields func extractResourceData(r resource.Resource) (map[string]interface{}, error) { // extract metadata - o, _ := resource.MarshalYAML(r) - m, _ := yaml.Marshal(o) - var res map[string]interface{} - - yaml.Unmarshal(m, &res) + o, err := resource.MarshalYAML(r) + if err != nil { + return nil, fmt.Errorf("failed to marshal resource to YAML: %w", err) + } + m, err := yaml.Marshal(o) + if err != nil { + return nil, fmt.Errorf("failed to marshal metadata to YAML: %w", err) + } + res := make(map[string]interface{}) + if err := yaml.Unmarshal(m, &res); err != nil { + return nil, fmt.Errorf("failed to unmarshal metadata: %w", err) + } // extract spec val := reflect.ValueOf(r.Spec()) From 616364ab6ef1bdccceb483301c06474325831bbc Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 23 Jan 2026 21:34:02 +0100 Subject: [PATCH 2/2] fix(lookup): propagate extractResourceData errors to multiErr Instead of silently swallowing errors from extractResourceData, append them to multiErr with resource type and ID for easier debugging. Co-Authored-By: Claude Signed-off-by: Andrei Kvapil --- pkg/engine/engine.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index d5a40e4..bcb30bd 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -612,6 +612,7 @@ func newLookupFunction(ctx context.Context, c *client.Client) func(resource stri res, err := extractResourceData(r) if err != nil { + multiErr = multierror.Append(multiErr, fmt.Errorf("resource %s/%s: %w", r.Metadata().Type(), r.Metadata().ID(), err)) return nil } @@ -626,6 +627,9 @@ func newLookupFunction(ctx context.Context, c *client.Client) func(resource stri if helperErr != nil { return map[string]interface{}{}, helperErr } + if err := multiErr.ErrorOrNil(); err != nil { + return map[string]interface{}{}, err + } if len(resources) == 0 { return map[string]interface{}{}, nil }