{"record":{"id":"dea308af754e41b4","repo":"kataras/iris","slug":"bad-value-could-not-resolve-a-dependency-from","errorCode":null,"errorMessage":"bad value: could not resolve a dependency from: %#+v","messagePattern":"bad value: could not resolve a dependency from: %#\\+v","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/dependency.go","lineNumber":115,"sourceCode":"\n\tv := valueOf(dependency)\n\tif !goodVal(v) {\n\t\tpanic(fmt.Sprintf(\"bad value: %#+v\", dependency))\n\t}\n\n\tif matchDependency == nil {\n\t\tmatchDependency = DefaultDependencyMatcher\n\t}\n\n\tdest := &Dependency{\n\t\tSource:           newSource(v),\n\t\tOriginalValue:    dependency,\n\t\tStructDependents: enableStructDependents,\n\t}\n\tdest.Match = ToDependencyMatchFunc(dest, matchDependency)\n\n\tif !resolveDependency(v, disablePayloadAutoBinding, dest, funcDependencies...) {\n\t\tpanic(fmt.Sprintf(\"bad value: could not resolve a dependency from: %#+v\", dependency))\n\t}\n\n\treturn dest\n}\n\n// DependencyResolver func(v reflect.Value, dest *Dependency) bool\n// Resolver     DependencyResolver\n\nfunc resolveDependency(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies ...*Dependency) bool {\n\treturn fromDependencyHandler(v, dest) ||\n\t\tfromBuiltinValue(v, dest) ||\n\t\tfromStructValueOrDependentStructValue(v, disablePayloadAutoBinding, dest, prevDependencies) ||\n\t\tfromFunc(v, dest) ||\n\t\tlen(prevDependencies) > 0 && fromDependentFunc(v, disablePayloadAutoBinding, dest, prevDependencies)\n}\n\nfunc fromDependencyHandler(_ reflect.Value, dest *Dependency) bool {\n\t// It's already on the desired form, just return it.","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/dependency.go#L97-L133","documentation":"After receiving a usable value, newDependency calls resolveDependency to figure out how to produce the dependency. If resolution fails (e.g. a function input cannot be bound to any known binding), it panics saying no dependency could be resolved from the given value.","triggerScenarios":"Registering a function whose input parameter types match no known binding (no matching registered dependency or request context type), with disablePayloadAutoBinding preventing auto-binding, via NewDependency/Register/BuiltinDependencies/getBindingsForStruct.","commonSituations":"A handler dependency function takes a custom type that was never registered; renaming/refactoring a service type so its registered binding no longer matches; spelling the expected input type differently from the registered one.","solutions":["Register the missing dependency type: c.Register(myService) so the function's inputs can be resolved.","Simplify the function signature so all inputs are types the container knows (or *iris.Context / context.Context).","If payload auto-binding was disabled, re-enable c.DisablePayloadAutoBinding = false or register the payload type explicitly.","Log/print the function signature and compare each input type against registered bindings."],"exampleFix":"// before\nfunc newSvc(cfg *Config) *Service { ... } // Config never registered\nc.Register(newSvc)\n// after\nc.Register(cfg)          // register the input first\nc.Register(newSvc)","handlingStrategy":"validation","validationCode":"// Before registering a factory func, check each input type has a binding:\nfor _, in := range reflect.TypeOf(factoryFn).NumIn() /* iterate Ins */ {\n\tif !c.CanInject(inType) { panic(\"no binding for \" + inType.String()) }\n}","typeGuard":"func allInputsBound(fn any, bound map[reflect.Type]bool) bool {\n\tt := reflect.TypeOf(fn)\n\tfor i := 0; i < t.NumIn(); i++ {\n\t\tif !bound[t.In(i)] { return false }\n\t}\n\treturn true\n}","tryCatchPattern":null,"preventionTips":["Register every type referenced by dependency-function inputs.","Keep a central list of registered types and review on refactor.","Avoid disabling payload auto-binding unless necessary."],"tags":["dependency-injection","unresolvable-dependency","panic","binding"],"backgroundTag":"unresolvable-dependency","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}