{"record":{"id":"6215c4ba1fedd8ca","repo":"kataras/iris","slug":"bad-value-v","errorCode":null,"errorMessage":"bad value: %#+v","messagePattern":"bad value: %#\\+v","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/dependency.go","lineNumber":100,"sourceCode":"func newDependency(\n\tdependency any,\n\tdisablePayloadAutoBinding bool,\n\tenableStructDependents bool,\n\tmatchDependency DependencyMatcher,\n\tfuncDependencies ...*Dependency,\n) *Dependency {\n\tif dependency == nil {\n\t\tpanic(fmt.Sprintf(\"bad value: nil: %T\", dependency))\n\t}\n\n\tif d, ok := dependency.(*Dependency); ok {\n\t\t// already a *Dependency, do not continue (and most importatly do not call resolveDependency) .\n\t\treturn d\n\t}\n\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","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/dependency.go#L82-L118","documentation":"newDependency panics when the value passed to Register/NewDependency is not of a usable kind (e.g. nil or an invalid reflect.Value). The hero DI container cannot build a Dependency from it, so it fails fast at registration time rather than at request time.","triggerScenarios":"Calling c.Register(nil), registering an unexported/nil-valued variable, or passing a value whose reflect kind fails goodVal() (invalid, nil pointer/interface/func without proper signature) to NewDependency, Register, or via getBindingsForStruct.","commonSituations":"Config mistakes like registering a struct field that is a nil pointer because an init step failed, typos where a nil variable is passed instead of its address, or refactorings that removed the value assigned before registration.","solutions":["Ensure the value passed to Register/NewDependency is non-nil and of a supported kind (pointer, func, struct, base type value).","If registering a pointer, initialize it first: dep := &MyStruct{}; c.Register(dep).","Check that you are not accidentally passing a typed nil (e.g. var h *Handler; c.Register(h)).","Wrap registration in a helper that asserts non-nil before calling Register."],"exampleFix":"// before\nvar logger *Logger // nil\nc.Register(logger) // panics: bad value\n// after\nlogger := NewLogger()\nif logger == nil { panic(\"logger not initialized\") }\nc.Register(logger)","handlingStrategy":"validation","validationCode":"func safeRegister(c *hero.Container, v any) {\n\tif v == nil || reflect.ValueOf(v).IsZero() {\n\t\tpanic(\"refusing to register nil/zero value\")\n\t}\n\tc.Register(v)\n}","typeGuard":"func isRegisterable(v any) bool {\n\trv := reflect.ValueOf(v)\n\tif !rv.IsValid() { return false }\n\tswitch rv.Kind() {\n\tcase reflect.Ptr, reflect.Interface, reflect.Map, reflect.Slice, reflect.Func, reflect.Chan:\n\t\treturn !rv.IsNil()\n\t}\n\treturn true\n}","tryCatchPattern":null,"preventionTips":["Never pass typed-nil pointers to Register.","Initialize dependencies before container setup.","Add an assert-non-nil helper for all registrations."],"tags":["dependency-injection","nil-value","panic","registration"],"backgroundTag":"invalid-dependency-value","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}