{"id":"e12ed4dcc0ca654f","repo":"gofiber/fiber","slug":"use-invalid-handler-v-e12ed4","errorCode":null,"errorMessage":"use: invalid handler %v\n","messagePattern":"use: invalid handler (.+?)\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"group.go","lineNumber":87,"sourceCode":"// This method will match all HTTP verbs: GET, POST, PUT, HEAD etc...\nfunc (grp *Group) Use(args ...any) Router {\n\tvar subApp *App\n\tvar prefix string\n\tvar prefixes []string\n\tvar handlers []Handler\n\n\tfor i := range args {\n\t\tswitch arg := args[i].(type) {\n\t\tcase string:\n\t\t\tprefix = arg\n\t\tcase *App:\n\t\t\tsubApp = arg\n\t\tcase []string:\n\t\t\tprefixes = arg\n\t\tdefault:\n\t\t\thandler, ok := toFiberHandler(arg)\n\t\t\tif !ok {\n\t\t\t\tpanic(fmt.Sprintf(\"use: invalid handler %v\\n\", reflect.TypeOf(arg)))\n\t\t\t}\n\t\t\thandlers = append(handlers, handler)\n\t\t}\n\t}\n\n\tif len(prefixes) == 0 {\n\t\tprefixes = append(prefixes, prefix)\n\t}\n\n\tfor _, prefix := range prefixes {\n\t\tif subApp != nil {\n\t\t\treturn grp.mount(prefix, subApp)\n\t\t}\n\n\t\tgrp.app.register([]string{methodUse}, getGroupPath(grp.Prefix, prefix), grp, handlers...)\n\t}\n\n\tif !grp.hasAnyRoute {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/group.go#L69-L105","documentation":"Group.Use accepts variadic arguments that may be a prefix string, a *App (for mounting), a []string (multiple prefixes), or a handler convertible via toFiberHandler (Fiber handlers, Express-style handlers, net/http handlers, fasthttp handlers). Any argument of an unsupported type panics with \"use: invalid handler\" and the Go type name.","triggerScenarios":"Passing a plain struct, an int, a string pointer, or any function signature not in the supported list to Group.Use(). Also triggered by passing a typed nil that isn't one of the recognized handler types.","commonSituations":"Passing an http.HandlerFunc where a fiber.Handler was expected is actually fine, but passing a custom middleware struct that doesn't implement a recognized signature fails. Wrapping a non-Fiber library middleware. Typos like passing a method value with the wrong signature.","solutions":["Pass only values of types toFiberHandler accepts: fiber.Handler, func(Ctx), the Express-style func(Req,Res,...) signatures, http.HandlerFunc/http.Handler, or fasthttp handler types.","Wrap custom middleware in an adapter returning fiber.Handler before passing to Use.","Check the reported Go type in the panic message to find the offending argument."],"exampleFix":"// before\ngrp.Use(myPlainStruct{})\n// after\ngrp.Use(func(c fiber.Ctx) error {\n    // adapt myPlainStruct behavior here\n    return c.Next()\n})","handlingStrategy":"type-guard","validationCode":"switch arg.(type) {\ncase string, *App, []string:\n    // ok\ncase fiber.Handler, func(fiber.Ctx),\n    func(Req, Res) error, func(Req, Res),\n    func(Req, Res, func() error) error, func(Req, Res, func() error),\n    func(Req, Res, func(error)), func(Req, Res, func(error)) error,\n    func(Req, Res, func(error) error), func(Req, Res, func(error) error) error,\n    http.HandlerFunc, http.Handler, func(http.ResponseWriter, *http.Request),\n    fasthttp.RequestHandler, func(*fasthttp.RequestCtx) error:\n    // ok\ndefault:\n    log.Fatalf(\"use: unsupported handler type %T\", arg)\n}","typeGuard":"func isUsableHandler(arg any) bool {\n    switch arg.(type) {\n    case string, *App, []string:\n        return true\n    default:\n        _, ok := toFiberHandlerPublic(arg) // mirror of internal adapter\n        return ok\n    }\n}","tryCatchPattern":null,"preventionTips":["Wrap non-Fiber middleware in an adapter returning fiber.Handler before passing to Use.","Read the panic message: it prints the Go type so you can identify the offending argument."],"tags":["routing","group","middleware","type-error","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}