{"id":"a80799cd5a1d862b","repo":"gofiber/fiber","slug":"use-invalid-handler-v-n","errorCode":null,"errorMessage":"use: invalid handler %v\\n","messagePattern":"use: invalid handler (.+?)\\\\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"app.go","lineNumber":1045,"sourceCode":"// This method will match all HTTP verbs: GET, POST, PUT, HEAD etc...\nfunc (app *App) Use(args ...any) Router {\n\tvar prefix string\n\tvar subApp *App\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 app.mount(prefix, subApp)\n\t\t}\n\n\t\tapp.register([]string{methodUse}, prefix, nil, handlers...)\n\t}\n\n\treturn app","sourceCodeStart":1027,"sourceCodeEnd":1063,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/app.go#L1027-L1063","documentation":"Panicked by app.Use (app.go:1045) when a variadic argument to app.Use(...) is not a recognized type (not a string prefix, not a *App, not a []string of prefixes, and not a convertible handler). The panic uses reflect.TypeOf(arg) to show the actual type so you can identify which argument was invalid.","triggerScenarios":"Calling app.Use with an unsupported argument type — e.g. app.Use(123), app.Use(someStruct), app.Use(func() {}) — or a method-value/interface whose signature is not in toFiberHandler's supported list. The default branch of the type switch (app.go:1042-1048) fires.","commonSituations":"Passing a non-handler middleware by mistake, a refactor that changed Use call sites, mixing up Use (which takes prefixes+handlers) with route methods, or passing an untyped nil wrapped in an interface.","solutions":["Read the panic: it prints the Go type of the bad argument — locate that argument in your app.Use call.","Ensure every non-prefix argument is a supported handler signature (see error 236).","Split prefix strings from handlers; app.Use(\"/api\", handler1, handler2).","Add explicit type checks or use fiber.Handler to keep signatures correct."],"exampleFix":"// before: passing a wrong type\napp.Use(\"/api\", myConfig)\n\n// after: only prefixes and handlers\napp.Use(\"/api\", authMiddleware, logMiddleware)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isUseArg(a any) bool {\n    switch a.(type) {\n    case string, []string, *fiber.App:\n        return true\n    default:\n        return isFiberHandler(a)\n    }\n}","tryCatchPattern":null,"preventionTips":["Only pass prefixes (string, []string), a *fiber.App to mount, or supported handlers to app.Use.","Keep middleware functions on the canonical Fiber signature.","Review every app.Use call site after refactors."],"tags":["middleware","use","handlers","panic","type-mismatch"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}