kataras/iris · error
bad value: %#+v
Error message
bad value: %#+v
What it means
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.
Source
Thrown at hero/dependency.go:100
func newDependency(
dependency any,
disablePayloadAutoBinding bool,
enableStructDependents bool,
matchDependency DependencyMatcher,
funcDependencies ...*Dependency,
) *Dependency {
if dependency == nil {
panic(fmt.Sprintf("bad value: nil: %T", dependency))
}
if d, ok := dependency.(*Dependency); ok {
// already a *Dependency, do not continue (and most importatly do not call resolveDependency) .
return d
}
v := valueOf(dependency)
if !goodVal(v) {
panic(fmt.Sprintf("bad value: %#+v", dependency))
}
if matchDependency == nil {
matchDependency = DefaultDependencyMatcher
}
dest := &Dependency{
Source: newSource(v),
OriginalValue: dependency,
StructDependents: enableStructDependents,
}
dest.Match = ToDependencyMatchFunc(dest, matchDependency)
if !resolveDependency(v, disablePayloadAutoBinding, dest, funcDependencies...) {
panic(fmt.Sprintf("bad value: could not resolve a dependency from: %#+v", dependency))
}
return destView on GitHub (pinned to 7bedaf55a0)
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.
Example fix
// before
var logger *Logger // nil
c.Register(logger) // panics: bad value
// after
logger := NewLogger()
if logger == nil { panic("logger not initialized") }
c.Register(logger) Defensive patterns
Strategy: validation
Validate before calling
func safeRegister(c *hero.Container, v any) {
if v == nil || reflect.ValueOf(v).IsZero() {
panic("refusing to register nil/zero value")
}
c.Register(v)
} Type guard
func isRegisterable(v any) bool {
rv := reflect.ValueOf(v)
if !rv.IsValid() { return false }
switch rv.Kind() {
case reflect.Ptr, reflect.Interface, reflect.Map, reflect.Slice, reflect.Func, reflect.Chan:
return !rv.IsNil()
}
return true
} Prevention
- Never pass typed-nil pointers to Register.
- Initialize dependencies before container setup.
- Add an assert-non-nil helper for all registrations.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- bad value: nil: %T
- api container: set dependency matcher: fn cannot be nil
- bindings: unresolved: no a func type: %#+v
- expected [%d] bindings (input parameters) but got [%d] Funct
- bindings: unresolved: not a struct type: %#+v
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/6215c4ba1fedd8ca.
Report an issue: GitHub.