{"record":{"id":"a7de5a6415cb57ae","repo":"kataras/iris","slug":"expected-d-bindings-input-parameters-but-got","errorCode":null,"errorMessage":"expected [%d] bindings (input parameters) but got [%d]\nFunction:\n  - %s\nExpected:%s\nMissing:%s","messagePattern":"expected \\[(.+?)\\] bindings \\(input parameters\\) but got \\[(.+?)\\]\nFunction:\n  - (.+?)\nExpected:(.+?)\nMissing:(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/binding.go","lineNumber":287,"sourceCode":"\t\tfor i, in := range inputs {\n\t\t\tpos := i + 1\n\t\t\ttypName := in.String()\n\t\t\texpectedInputs += fmt.Sprintf(\"\\n  - [%d] %s\", pos, typName)\n\t\t\tfound := false\n\t\t\tfor _, b := range bindings {\n\t\t\t\tif b.Input.Index == i {\n\t\t\t\t\tfound = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif !found {\n\t\t\t\tmissingInputs += fmt.Sprintf(\"\\n  - [%d] %s\", pos, typName)\n\t\t\t}\n\t\t}\n\n\t\tfnName := context.HandlerName(fn)\n\t\tpanic(fmt.Sprintf(\"expected [%d] bindings (input parameters) but got [%d]\\nFunction:\\n  - %s\\nExpected:%s\\nMissing:%s\",\n\t\t\texpected, got, fnName, expectedInputs, missingInputs))\n\t}\n\n\treturn bindings\n}\n\nfunc getBindingsForStruct(v reflect.Value, dependencies []*Dependency, markExportedFieldsAsRequired bool, disablePayloadAutoBinding, enableStructDependents bool, matchDependency DependencyMatcher, paramsCount int, sorter Sorter) (bindings []*binding) {\n\ttyp := indirectType(v.Type())\n\tif typ.Kind() != reflect.Struct {\n\t\tpanic(fmt.Sprintf(\"bindings: unresolved: not a struct type: %#+v\", v))\n\t}\n\n\t// get bindings from any struct's non zero values first, including unexported.\n\telem := reflect.Indirect(v)\n\tnonZero := lookupNonZeroFieldValues(elem)\n\tfor _, f := range nonZero {\n\t\t// fmt.Printf(\"Controller [%s] | NonZero | Field Index: %v | Field Type: %s\\n\", typ, f.Index, f.Type)\n\t\tbindings = append(bindings, &binding{","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/binding.go#L269-L305","documentation":"hero resolves each of a handler function's input parameters into a binding backed by a dependency. If the number of resolved bindings does not equal the number of function inputs, some parameter could not be matched to any registered dependency (or payload binding), so hero panics with a detailed expected/missing report to prevent a broken handler from ever serving requests.","triggerScenarios":"Registering a handler whose parameters' types are not covered by Container.Register dependency functions or built-in bindings (e.g. a custom *Service parameter with no matching dependency, an unexported/unsupported param type), or registering a dependency whose return type does not exactly match the parameter type under the default matcher, or disabling payload auto-binding while the handler expects a request payload struct.","commonSituations":"Forgetting Container.Register for a custom service type; a dependency registered for an interface type while the handler asks for the concrete type (or vice versa); renaming a service type after refactor; typo in generic type parameters; handler takes a context-independent param that hero cannot infer (like *http.Request wrappers); missing Singleton dependency after DI refactor.","solutions":["Read the Missing list in the panic: it names each unmatched input parameter type; register a dependency for each, e.g. c.Container.Register(func() *Service { return NewService() }).","Register the dependency with Container.Register before calling Container.Handler.","If the parameter should come from the request payload, ensure it is a supported payload type (struct/slice/ptr) and that payload auto-binding is not disabled via hero.DisablePayloadAutoBinding.","Check that the dependency's return type exactly matches the handler's parameter type (pointer vs value, interface vs concrete).","Use hero's Reporter for a detailed diagnostic of what could be bound.","Mark truly optional/unmatched params differently or remove them from the handler signature."],"exampleFix":"// before\nfunc handler(svc *MyService) {} // panics: *MyService not bindable\n// after\ncontainer.Register(func() *MyService { return NewMyService() })\napp.Party(\"/\").ConfigureContainer(container).Handler(handler)","handlingStrategy":"validation","validationCode":"// sanity check before registering the handler\nrv := reflect.TypeOf(handler)\nfor i := 0; i < rv.NumIn(); i++ {\n    in := rv.In(i)\n    if !container.HasDependencyFor(in) { // or check against your registered deps\n        log.Printf(\"warning: handler param %s has no registered dependency\", in)\n    }\n}","typeGuard":"func canBindInputs(fn any, deps ...any) bool {\n    t := reflect.TypeOf(fn)\n    if t == nil || t.Kind() != reflect.Func { return false }\n    provided := map[reflect.Type]bool{}\n    for _, d := range deps { provided[reflect.TypeOf(d)] = true }\n    for i := 0; i < t.NumIn(); i++ {\n        if !provided[t.In(i)] { return false }\n    }\n    return true\n}","tryCatchPattern":"func safeRegister(h any) (ok bool) {\n    defer func() {\n        if r := recover(); r != nil {\n            if s, isStr := r.(string); isStr && strings.Contains(s, \"bindings\") {\n                log.Printf(\"handler binding failed: %s\", s)\n            } else { panic(r) }\n        }\n    }()\n    container.Handler(h)\n    return true\n}","preventionTips":["Register every service dependency before wiring handlers.","Match dependency return types exactly to handler parameter types (pointer vs value).","Run container.Report(os.Stdout) at startup to catch missing bindings early.","Avoid disabling payload auto-binding unless all payload params are explicitly handled.","Keep handler signatures limited to types hero knows how to bind."],"tags":["go","dependency-injection","binding","panic","unresolved-dependency"],"backgroundTag":"unresolved-dependency-binding","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}