diff --git a/pkg/factsengine/entities/fact_value.go b/pkg/factsengine/entities/fact_value.go index a346ebfc..4d429aab 100644 --- a/pkg/factsengine/entities/fact_value.go +++ b/pkg/factsengine/entities/fact_value.go @@ -193,7 +193,7 @@ func getValue(fact FactValue, values []string) (FactValue, error) { } return getValue(value.Value[listIndex], values[1:]) default: - return value, nil + return nil, fmt.Errorf("requested field value not found") } } diff --git a/pkg/factsengine/entities/fact_value_test.go b/pkg/factsengine/entities/fact_value_test.go index 65bfaa9c..a936f46d 100644 --- a/pkg/factsengine/entities/fact_value_test.go +++ b/pkg/factsengine/entities/fact_value_test.go @@ -182,6 +182,7 @@ func (suite *FactValueTestSuite) TestFactValueMapGetValue() { "value": &entities.FactValueString{Value: "other_value"}, }, }, + "empty_entry": &entities.FactValueString{}, }, } @@ -252,6 +253,15 @@ func (suite *FactValueTestSuite) TestFactValueMapGetValue() { Message: "error getting value: requested field value not found: map_value.other_value", }, }, + { + description: "Should return ValueNotFoundError when value does not exist because the entry is empty", + key: "empty_entry.some_value", + expected: nil, + err: &entities.FactGatheringError{ + Type: "value-not-found", + Message: "error getting value: requested field value not found: empty_entry.some_value", + }, + }, { description: "Should return ValueNotFoundError when given list index does not exist", key: "list_value.3",