{"record":{"id":"d46fc297cdd4a69b","repo":"kataras/iris","slug":"makehandler-function-is-nil","errorCode":null,"errorMessage":"makeHandler: function is nil","messagePattern":"makeHandler: function is nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hero/handler.go","lineNumber":98,"sourceCode":"\t\t\t_, _ = ctx.WriteString(err.Error())\n\t\t}\n\n\t\tctx.StopExecution()\n\t})\n)\n\nvar (\n\tirisHandlerType     = reflect.TypeOf((*context.Handler)(nil)).Elem()\n\tirisHandlerFuncType = reflect.TypeOf(func(*context.Context) {})\n)\n\nfunc isIrisHandlerType(typ reflect.Type) bool {\n\treturn typ == irisHandlerType || typ == irisHandlerFuncType\n}\n\nfunc makeHandler(fn any, c *Container, paramsCount int) context.Handler {\n\tif fn == nil {\n\t\tpanic(\"makeHandler: function is nil\")\n\t}\n\n\t// 0. A normal handler.\n\tif handler, ok := isHandler(fn); ok {\n\t\treturn handler\n\t}\n\n\t// 1. A handler which returns just an error, handle it faster.\n\tif handlerWithErr, ok := isHandlerWithError(fn); ok {\n\t\treturn func(ctx *context.Context) {\n\t\t\tif err := handlerWithErr(ctx); err != nil {\n\t\t\t\tc.GetErrorHandler(ctx).HandleError(ctx, err)\n\t\t\t}\n\t\t}\n\t}\n\n\tv := valueOf(fn)\n\ttyp := v.Type()","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/hero/handler.go#L80-L116","documentation":"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.","triggerScenarios":"Calling c.Handler(nil), HandlerWithParams(nil, ...), or MethodHandler with a nil method value (e.g. an interface method on a nil struct pointer).","commonSituations":"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.","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."],"exampleFix":"// before\nvar handler context.Handler // nil\napp.Handle(\"GET\", \"/\", handler)\n// after\nhandler := myController.Index\nif handler == nil { panic(\"handler not set\") }\napp.Handle(\"GET\", \"/\", handler)","handlingStrategy":"validation","validationCode":"if handlerFn == nil { panic(\"handler function not initialized\") }\napp.Handle(\"GET\", \"/\", handlerFn)","typeGuard":"func nonNilHandler(fn any) bool { return fn != nil && !reflect.ValueOf(fn).IsNil() }","tryCatchPattern":null,"preventionTips":["Assert non-nil before registering handlers.","Initialize controllers before route registration.","Avoid typed-nil func variables."],"tags":["http-handler","nil-function","panic","hero"],"backgroundTag":"nil-handler-function","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}