{"record":{"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/a105acad6c1e4576a77f01e02973f67e962bb58d/group.go#L69-L105","documentation":"Group.Use accepts the same argument shapes as App.Use: string prefix, []string prefixes, *App sub-app, and handlers convertible via toFiberHandler (Fiber, Express-style, net/http, fasthttp signatures). Anything else — including nil and unsupported func signatures — falls through to the default branch and panics, printing reflect.TypeOf(arg). The message differs from the domain variant only by a trailing '\\n'.","triggerScenarios":"Calling grp.Use(...) with an argument whose dynamic type matches none of the switch cases — e.g. an int, a struct, a chan, a typed-nil handler, or a func with an unsupported signature (wrong arity, wrong return type, pointer-to-interface receiver).","commonSituations":"Passing a typed-nil middleware (var mw MyMw = nil); a handler with signature drift after a fiber major-version upgrade (e.g. v2 func(*fiber.Ctx) into v3 which uses the Ctx interface); leaving a debug placeholder integer/zero-struct in the middleware chain; wrapping a handler in a custom type that hides the underlying func signature.","solutions":["Convert the argument to a supported signature, preferably fiber.Handler (func(Ctx) error).","For net/http handlers, pass the value directly only when its static type is exactly http.HandlerFunc/http.Handler/func(http.ResponseWriter,*http.Request); otherwise adapt it.","Eliminate typed-nil middleware values; pass a real handler or omit the argument."],"exampleFix":"// before\ngrp.Use(\"/x\", myStruct{})\ngrp.Use(\"/x\", func(c *fiber.Ctx) error { return nil }) // v2-style\n// after\ngrp.Use(\"/x\", func(c fiber.Ctx) error { return nil })","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// same shape as error 264; reuse isUseArg for Group.Use arguments.\nfor _, a := range args {\n    if !isUseArg(a) {\n        return fmt.Errorf(\"unsupported Group.Use arg %T\", a)\n    }\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"Group.Use arg rejected: %v\", r)\n    }\n}()\ngrp.Use(args...)","preventionTips":["After a fiber major-version upgrade, grep all handler signatures for the old receiver/return types.","Pass fiber.Handler (func(Ctx) error) consistently to avoid signature drift.","Reject typed-nil middleware at the composition layer with a non-nil assertion."],"tags":["routing","group","handler","type-mismatch","startup"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}