{"record":{"id":"4b0711e79103b72c","repo":"kataras/iris","slug":"passed-handler-cannot-be-converted-directly","errorCode":null,"errorMessage":"\n\t\t\tPassed handler cannot be converted directly:\n\t\t\t- http.Handler(http.Handler)\n\t\t\t---------------------------------------------------------------------\n\t\t\tPlease use the Application.WrapRouter method instead, example code:\n\t\t\tapp := iris.New()\n\t\t\t// ...\n\t\t\tapp.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {\n\t\t\t    httpThirdPartyHandler(router).ServeHTTP(w, r)\n\t\t\t})","messagePattern":"\n\t\t\tPassed handler cannot be converted directly:\n\t\t\t- http\\.Handler\\(http\\.Handler\\)\n\t\t\t---------------------------------------------------------------------\n\t\t\tPlease use the Application\\.WrapRouter method instead, example code:\n\t\t\tapp := iris\\.New\\(\\)\n\t\t\t// \\.\\.\\.\n\t\t\tapp\\.WrapRouter\\(func\\(w http\\.ResponseWriter, r \\*http\\.Request, router http\\.HandlerFunc\\) (.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlerconv/from_std.go","lineNumber":36,"sourceCode":"\tswitch h := handler.(type) {\n\tcase context.Handler:\n\t\treturn h\n\t// case func(*context.Context):\n\t// \treturn h\n\tcase http.Handler:\n\t\t// handlerFunc.ServeHTTP(w,r)\n\t\treturn func(ctx *context.Context) {\n\t\t\th.ServeHTTP(ctx.ResponseWriter(), ctx.Request())\n\t\t}\n\tcase func(http.ResponseWriter, *http.Request):\n\t\t// handlerFunc(w,r)\n\t\treturn FromStd(http.HandlerFunc(h))\n\tcase func(http.ResponseWriter, *http.Request, http.HandlerFunc):\n\t\t// handlerFunc(w,r, http.HandlerFunc)\n\t\t//\n\t\treturn FromStdWithNext(h)\n\tcase func(http.Handler) http.Handler:\n\t\tpanic(fmt.Errorf(`\n\t\t\tPassed handler cannot be converted directly:\n\t\t\t- http.Handler(http.Handler)\n\t\t\t---------------------------------------------------------------------\n\t\t\tPlease use the Application.WrapRouter method instead, example code:\n\t\t\tapp := iris.New()\n\t\t\t// ...\n\t\t\tapp.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {\n\t\t\t    httpThirdPartyHandler(router).ServeHTTP(w, r)\n\t\t\t})`))\n\tdefault:\n\t\t// No valid handler passed\n\t\tpanic(fmt.Errorf(`\n\t\t\tPassed argument is not a func(iris.Context) neither one of these types:\n\t\t\t- http.Handler\n\t\t\t- func(w http.ResponseWriter, r *http.Request)\n\t\t\t- func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)\n\t\t\t---------------------------------------------------------------------\n\t\t\tIt seems to be a %T points to: %v`, handler, handler))","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/core/handlerconv/from_std.go#L18-L54","documentation":"FromStd panics when handed a func(http.Handler) http.Handler (middleware-style adapter) because it cannot be converted to an iris handler directly — it wraps the router rather than a handler. The library directs you to Application.WrapRouter instead.","triggerScenarios":"Calling handlerconv.FromStd (or app.Use/Handle with) a third-party middleware of type func(http.Handler) http.Handler, e.g. alice-style or gorilla middleware, promhttp.InstrumentHandlerDuration-style adapters.","commonSituations":"Mounting go chi/negroni/alice middleware on an iris app; passing a net/http middleware chain as if it were a plain handler.","solutions":["Register the middleware via app.WrapRouter, adapting it: app.WrapRouter(func(w, r, router){ myMiddleware(http.HandlerFunc(router)).ServeHTTP(w, r) }).","If the middleware can be invoked with a final handler, wrap the iris route handler instead of the router.","Convert to an iris-native handler using iris.FromStdWithNext-style semantics or rewrite the middleware for iris."],"exampleFix":"// before\napp.UseRouter(fromStd(middleware)) // func(http.Handler) http.Handler -> panic\n// after\napp.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {\n    middleware(http.HandlerFunc(router)).ServeHTTP(w, r)\n})","handlingStrategy":"type-guard","validationCode":"// detect middleware-style adapters\nswitch h.(type) {\ncase func(http.Handler) http.Handler:\n    // must go through app.WrapRouter, not FromStd/Use\n}","typeGuard":"func isHandlerMiddleware(v interface{}) bool {\n    _, ok := v.(func(http.Handler) http.Handler)\n    return ok\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"cannot be converted directly\") {\n            log.Fatal(\"use app.WrapRouter for func(http.Handler) http.Handler middleware\")\n        }\n        panic(r)\n    }\n}()","preventionTips":["Register func(http.Handler) http.Handler middleware via app.WrapRouter","Know the middleware type from the third-party library's docs","Don't pass net/http middleware chains where iris handlers are expected"],"tags":["panic","http-middleware","handler-conversion"],"backgroundTag":"invalid-handler-type","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}