kataras/iris · error
args(len=%d) should be the same len as numFields(%d) for: %s
Error message
args(len=%d) should be the same len as numFields(%d) for: %s
What it means
A macro evaluator defined over a struct requires exactly one route argument per struct field; when the number of supplied arguments differs from the struct's field count, the route panics with 'args(len=%d) should be the same len as numFields(%d)' (macro/macro.go:137). Variadic argument counts are not supported.
Source
Thrown at macro/macro.go:137
return fnV
}
}
return nil
}
numFields := typFn.NumIn()
panicIfErr := func(i int, err error) {
if err != nil {
panic(fmt.Sprintf("on field index: %d: %v", i, err))
}
}
return func(args []string) reflect.Value {
if len(args) != numFields {
// no variadics support, for now.
panic(fmt.Sprintf("args(len=%d) should be the same len as numFields(%d) for: %s", len(args), numFields, typFn))
}
var argValues []reflect.Value
for i := 0; i < numFields; i++ {
field := typFn.In(i)
arg := args[i]
// try to convert the string literal as we get it from the parser.
var (
val any
)
// try to get the value based on the expected type.
switch field.Kind() {
case reflect.Int:
v, err := strconv.Atoi(arg)
panicIfErr(i, err)
val = v
case reflect.Int8:View on GitHub (pinned to 7bedaf55a0)
Solutions
- Supply exactly as many space-separated arguments in the path parameter as the evaluator struct has fields.
- Reduce the evaluator struct to only the fields you actually pass in routes.
- Update all routes that use this param type after changing the struct's field count.
Example fix
// before (evaluator struct has Min and Max)
app.Get("/{n:number 10}", h)
// after
app.Get("/{n:number 1 10}", h) Defensive patterns
Strategy: validation
Validate before calling
// Count fields of the evaluator struct and compare with args in the path
t := reflect.TypeOf(MyEvaluator{})
nArgs := len(strings.Fields(paramArgs))
if nArgs != t.NumField() {
log.Fatalf("param needs %d args, got %d", t.NumField(), nArgs)
} Prevention
- Provide exactly one argument per evaluator-struct field, in field order.
- Grep routes after adding/removing evaluator fields and update all usages.
- Document the required argument list next to the custom param type.
When it happens
Trigger: Registering a macro type whose evaluator function takes a struct with N fields, then using the type in a path with fewer or more than N arguments, e.g. {range:number 5} when the evaluator struct has two fields (min, max).
Common situations: Omitting one of the arguments (e.g. writing {ts:number 100} instead of {ts:number 100 200} for a min-max evaluator), or adding a field to the evaluator struct without updating every route using it.
Related errors
- %T does not allow any input arguments from route but got [le
- %s: invalid path part: dynamic path parameter and other para
- %s: parameter type "%s" should be registered to the very end
- iris: switch: hosts: invalid target type: %T
- <appName> is not a registered Application
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/5a7a6d86950e1e7b.
Report an issue: GitHub.