{"record":{"id":"edcf97b96f18f135","repo":"kataras/iris","slug":"on-field-index-d-v","errorCode":null,"errorMessage":"on field index: %d: %v","messagePattern":"on field index: (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"macro/macro.go","lineNumber":130,"sourceCode":"\t\t\t// if that param type function is used wrongly it will be panic like the rest,\n\t\t\t// indeed the only check is the len of arguments not > 0, no types of values or conversions,\n\t\t\t// so we return it as soon as possible.\n\t\t\treturn func(args []string) reflect.Value {\n\t\t\t\tif n := len(args); n > 0 {\n\t\t\t\t\tpanic(fmt.Sprintf(\"%T does not allow any input arguments from route but got [len=%d,values=%s]\", fn, n, strings.Join(args, \", \")))\n\t\t\t\t}\n\t\t\t\treturn fnV\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tnumFields := typFn.NumIn()\n\n\tpanicIfErr := func(i int, err error) {\n\t\tif err != nil {\n\t\t\tpanic(fmt.Sprintf(\"on field index: %d: %v\", i, err))\n\t\t}\n\t}\n\n\treturn func(args []string) reflect.Value {\n\t\tif len(args) != numFields {\n\t\t\t// no variadics support, for now.\n\t\t\tpanic(fmt.Sprintf(\"args(len=%d) should be the same len as numFields(%d) for: %s\", len(args), numFields, typFn))\n\t\t}\n\t\tvar argValues []reflect.Value\n\t\tfor i := 0; i < numFields; i++ {\n\t\t\tfield := typFn.In(i)\n\t\t\targ := args[i]\n\n\t\t\t// try to convert the string literal as we get it from the parser.\n\t\t\tvar (\n\t\t\t\tval any\n\t\t\t)\n","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/macro/macro.go#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the wrapped %v error to find which field evaluator failed and fix its input/configuration.","Validate all field evaluator inputs (allowed values, ranges) before registering the macro type.","Simplify the evaluator struct so each field uses built-in evaluators known to succeed for your inputs."],"exampleFix":"// before\nEvaluator: func(m MyArgs) bool { /* m.Enum field evaluator errors on bad config */ }\n\n// after\n// validate enum values before registration\nif !validEnum(m.Enum) { return fmt.Errorf(\"bad enum\") }","handlingStrategy":"validation","validationCode":"// Validate each struct field's evaluator config before registering the macro\nfor i, ev := range fieldEvaluators {\n    if err := ev.Validate(); err != nil {\n        log.Fatalf(\"field %d invalid: %v\", i, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"macro evaluator field error: %v\", r)\n    }\n}()","preventionTips":["Pre-validate custom evaluator inputs (enums, ranges) before macro registration.","Test custom macro types standalone before wiring them into routes.","Keep evaluator struct fields simple with built-in evaluator functions."],"tags":["go","panic","reflection","path-parameters"],"backgroundTag":"macro-evaluator-error","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}