2023-02-06 07:27:27 +01:00
|
|
|
package jmespath
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
|
|
|
func validateArg(f string, arguments []interface{}, index int, expectedType reflect.Kind) (reflect.Value, error) {
|
2023-02-06 12:39:53 +01:00
|
|
|
if index >= len(arguments) {
|
2023-02-06 15:13:44 +01:00
|
|
|
return reflect.Value{}, formatError(argOutOfBoundsError, f, index+1, len(arguments))
|
2023-02-06 12:39:53 +01:00
|
|
|
}
|
2023-02-06 07:27:27 +01:00
|
|
|
arg := reflect.ValueOf(arguments[index])
|
|
|
|
if arg.Type().Kind() != expectedType {
|
2023-02-06 15:13:44 +01:00
|
|
|
return reflect.Value{}, formatError(invalidArgumentTypeError, f, index+1, expectedType.String())
|
2023-02-06 07:27:27 +01:00
|
|
|
}
|
|
|
|
return arg, nil
|
|
|
|
}
|