{"record":{"id":"7ceccf676e169618","repo":"kataras/iris","slug":"struct-method-s-does-not-exist","errorCode":null,"errorMessage":"struct: method: %s does not exist","messagePattern":"struct: method: (.+?) does not exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/struct.go","lineNumber":185,"sourceCode":"\t\t\t\t} // #1629\n\t\t\t}\n\n\t\t\telem.FieldByIndex(b.Input.StructFieldIndex).Set(input)\n\t\t}\n\t}\n\n\treturn ctrl, nil\n}\n\n// MethodHandler accepts a \"methodName\" that should be a valid an exported\n// method of the struct and returns its converted Handler.\n//\n// Second input is optional,\n// even zero is a valid value and can resolve path parameters correctly if from root party.\nfunc (s *Struct) MethodHandler(methodName string, paramsCount int) context.Handler {\n\tm, ok := s.ptrValue.Type().MethodByName(methodName)\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"struct: method: %s does not exist\", methodName))\n\t}\n\n\treturn makeHandler(m.Func, s.Container, paramsCount)\n}\n","sourceCodeStart":167,"sourceCodeEnd":190,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/struct.go#L167-L190","documentation":"Struct.MethodHandler panics when the requested methodName does not exist as an exported method on the registered struct's concrete type (hero/struct.go:185). It uses reflect Type.MethodByName, so only exported methods with a method-value receiver are found.","triggerScenarios":"Calling s.MethodHandler(\"Name\", n) where Name is misspelled, unexported, defined on an embedded/unrelated type, or the handler was built from an interface type that lacks the method.","commonSituations":"Refactoring renames a controller method without updating the manual MethodHandler registration; registering handlers on a struct via routes that reference methods with different casing.","solutions":["Verify the method name spelling and that it is exported (starts with an uppercase letter).","Ensure the method is defined on the exact type registered with the hero Struct, not only on an embedded or interface type.","Use route registration by method reference (e.g. app.Get(\"/\", c.Handler)) so the compiler catches missing methods instead of string lookup.","Add a test that builds all MethodHandler registrations at startup so the panic surfaces early."],"exampleFix":"// before\nh := s.MethodHandler(\"Indexx\", 0) // typo\n\n// after\nh := s.MethodHandler(\"Index\", 0)","handlingStrategy":"validation","validationCode":"// Check the method exists before requesting a handler\nif _, ok := reflect.TypeOf(MyController{}).MethodByName(\"Index\"); !ok {\n    log.Fatal(\"controller method Index not found\")\n}\nh := s.MethodHandler(\"Index\", 0)","typeGuard":"func hasMethod(obj interface{}, name string) bool {\n    return reflect.ValueOf(obj).MethodByName(name).IsValid()\n}","tryCatchPattern":null,"preventionTips":["Prefer typed route registration (app.Get(\"/\", c.Index)) over string-based MethodHandler.","Keep method names in sync with registrations; avoid unexported methods for handlers.","Add a startup smoke test that builds every route."],"tags":["go","reflection","panic","routing"],"backgroundTag":"method-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}