kataras/iris · error
makeHandler: function is nil
Error message
makeHandler: function is nil
What it means
makeHandler requires a non-nil function/value to convert into an Iris request handler. A nil fn produces an unusable handler, so it panics immediately.
Source
Thrown at hero/handler.go:98
_, _ = ctx.WriteString(err.Error())
}
ctx.StopExecution()
})
)
var (
irisHandlerType = reflect.TypeOf((*context.Handler)(nil)).Elem()
irisHandlerFuncType = reflect.TypeOf(func(*context.Context) {})
)
func isIrisHandlerType(typ reflect.Type) bool {
return typ == irisHandlerType || typ == irisHandlerFuncType
}
func makeHandler(fn any, c *Container, paramsCount int) context.Handler {
if fn == nil {
panic("makeHandler: function is nil")
}
// 0. A normal handler.
if handler, ok := isHandler(fn); ok {
return handler
}
// 1. A handler which returns just an error, handle it faster.
if handlerWithErr, ok := isHandlerWithError(fn); ok {
return func(ctx *context.Context) {
if err := handlerWithErr(ctx); err != nil {
c.GetErrorHandler(ctx).HandleError(ctx, err)
}
}
}
v := valueOf(fn)
typ := v.Type()View on GitHub (pinned to 7bedaf55a0)
Solutions
- Verify the function is assigned before registering: if h == nil { panic } before c.Handler(h).
- Check controller initialization order so method values are non-nil.
- For interface methods, ensure the concrete controller is initialized.
Example fix
// before
var handler context.Handler // nil
app.Handle("GET", "/", handler)
// after
handler := myController.Index
if handler == nil { panic("handler not set") }
app.Handle("GET", "/", handler) Defensive patterns
Strategy: validation
Validate before calling
if handlerFn == nil { panic("handler function not initialized") }
app.Handle("GET", "/", handlerFn) Type guard
func nonNilHandler(fn any) bool { return fn != nil && !reflect.ValueOf(fn).IsNil() } Prevention
- Assert non-nil before registering handlers.
- Initialize controllers before route registration.
- Avoid typed-nil func variables.
When it happens
Trigger: Calling c.Handler(nil), HandlerWithParams(nil, ...), or MethodHandler with a nil method value (e.g. an interface method on a nil struct pointer).
Common situations: A controller field/method that is nil because initialization failed; conditional assignment left the handler unset; a typed-nil func variable var h func(ctx iris.Context) passed directly.
Related errors
- makeHandler: func(...<T>) iris.Handler: expected %d function
- toml: %w
- toml :%w
- unexpected "fsOrDir" argument type of %T (string or fs.FS or
- Passed handler cannot be converted directly: - http.H
AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30).
Data as JSON: /api/errors/d46fc297cdd4a69b.
Report an issue: GitHub.