Force fail when a parameter is missing.
mschmidt4 opened this issue · 1 comments
Scenario:
I am evaluating " a && b " with map[string]interface{}{"a":true} and i'm getting false.
If I pass to the function an alias for map[string]interface{}, like
type Values map[string]interface{}
with "a":true and without B, I get an error saying:
can not evaluate a && b: unknown parameter b
And this is exactly what we want instead of a nil in the error because we prefer an error instead of a partial evaluation; In other words, we want all the parameters before doing the evaluation.
Is there a way to force the library to fail if some parameter is missing, using a map[string]interface{}. Otherwise, is safety use an alias to map[string]interface{} to check this errors?
You can write and use a custom variable selector that does exactly that. Just return a evaluable that handles maps and the other types you need and fails when it can't find the element that is indicated via path. See:
https://godoc.org/github.com/PaesslerAG/gval#VariableSelector