1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/engine/jmespath/utils.go
Charles-Edouard Brétéché dd35ae201b
fix: error management in jp functions (#6239)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-02-06 14:13:44 +00:00

16 lines
479 B
Go

package jmespath
import (
"reflect"
)
func validateArg(f string, arguments []interface{}, index int, expectedType reflect.Kind) (reflect.Value, error) {
if index >= len(arguments) {
return reflect.Value{}, formatError(argOutOfBoundsError, f, index+1, len(arguments))
}
arg := reflect.ValueOf(arguments[index])
if arg.Type().Kind() != expectedType {
return reflect.Value{}, formatError(invalidArgumentTypeError, f, index+1, expectedType.String())
}
return arg, nil
}