kataras/iris · error

on field index: %d: %v

Error message

on field index: %d: %v

What it means

When a macro type is registered with an evaluator whose input is a struct, the library validates each struct field's evaluator function and panics with 'on field index: %d: %v' if any field-level evaluator returns an error (macro/macro.go:130, in the panicIfErr helper). It wraps the underlying field error with its index for diagnosis.

Source

Thrown at macro/macro.go:130

			// if that param type function is used wrongly it will be panic like the rest,
			// indeed the only check is the len of arguments not > 0, no types of values or conversions,
			// so we return it as soon as possible.
			return func(args []string) reflect.Value {
				if n := len(args); n > 0 {
					panic(fmt.Sprintf("%T does not allow any input arguments from route but got [len=%d,values=%s]", fn, n, strings.Join(args, ", ")))
				}
				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
			)

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Read the wrapped %v error to find which field evaluator failed and fix its input/configuration.
  2. Validate all field evaluator inputs (allowed values, ranges) before registering the macro type.
  3. Simplify the evaluator struct so each field uses built-in evaluators known to succeed for your inputs.

Example fix

// before
Evaluator: func(m MyArgs) bool { /* m.Enum field evaluator errors on bad config */ }

// after
// validate enum values before registration
if !validEnum(m.Enum) { return fmt.Errorf("bad enum") }
Defensive patterns

Strategy: validation

Validate before calling

// Validate each struct field's evaluator config before registering the macro
for i, ev := range fieldEvaluators {
    if err := ev.Validate(); err != nil {
        log.Fatalf("field %d invalid: %v", i, err)
    }
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        log.Fatalf("macro evaluator field error: %v", r)
    }
}()

Prevention

When it happens

Trigger: Registering a custom macro type whose evaluator takes a struct with fields that are themselves macros/evaluators; one field's evaluator fails during registration or route-time validation.

Common situations: Custom param-type builders where a field evaluator (e.g. an enum or range parser) receives invalid configuration, surfacing as an indexed panic rather than a plain error.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/edcf97b96f18f135. Report an issue: GitHub.