diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index 91bbde4735..9b4674d9de 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -430,7 +430,11 @@ func (c compiledGauge) value(it interface{}) (*eachValue, error) { Value: 0, }, nil } - // Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup. + // no it means no iterables were passed down, meaning that the path resolution never happened + if it == nil { + return nil, fmt.Errorf("got nil while resolving path") + } + // Don't error if there was not a type-casting issue (`toFloat64`). return nil, nil } value, err := toFloat64(got, c.NilIsZero) diff --git a/pkg/customresourcestate/registry_factory_test.go b/pkg/customresourcestate/registry_factory_test.go index bce47c1c4e..c1d6f1621c 100644 --- a/pkg/customresourcestate/registry_factory_test.go +++ b/pkg/customresourcestate/registry_factory_test.go @@ -18,6 +18,7 @@ package customresourcestate import ( "encoding/json" + "errors" "reflect" "testing" @@ -194,6 +195,17 @@ func Test_values(t *testing.T) { }, wantResult: []eachValue{ newEachValue(t, 1.6563744e+09), }}, + {name: "non-existent path", each: &compiledGauge{ + compiledCommon: compiledCommon{ + path: mustCompilePath(t, "foo"), + labelFromPath: map[string]valuePath{ + "name": mustCompilePath(t, "name"), + }, + }, + ValueFrom: mustCompilePath(t, "creationTimestamp"), + }, wantResult: nil, wantErrors: []error{ + errors.New("[foo]: got nil while resolving path"), + }}, {name: "array", each: &compiledGauge{ compiledCommon: compiledCommon{ path: mustCompilePath(t, "status", "condition_values"),