{"record":{"id":"e1e0746876d6937e","repo":"gofiber/fiber","slug":"use-invalid-handler-v-e1e074","errorCode":null,"errorMessage":"use: invalid handler %v","messagePattern":"use: invalid handler (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"domain.go","lineNumber":367,"sourceCode":"//\t})\nfunc (d *domainRouter) 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 []string:\n\t\t\tprefixes = arg\n\t\tcase *App:\n\t\t\tsubApp = 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\", 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 d.mount(prefix, subApp)\n\t\t}\n\n\t\twrapped := d.wrapHandlers(handlers)\n\t\td.app.register([]string{methodUse}, d.registerPath(prefix), d.registerGroup(), wrapped...)\n\t}\n","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/domain.go#L349-L385","documentation":"fiber/v3's domainRouter.Use accepts string prefixes, []string of prefixes, *App sub-apps, and handler values convertible by toFiberHandler (Fiber handlers, Express-style func(Req,Res,...), net/http handlers, fasthttp handlers). Any other type — or nil — reaches the default branch and panics with the offending type. The message prints reflect.TypeOf(arg) so you can see exactly what was passed.","triggerScenarios":"Calling d.Use(...) on a domain router and passing an argument whose static type is not string, []string, or *App, and whose dynamic type is not one of the ~17 supported handler signatures — e.g. an int, a struct value, a chan, a bare nil (which has no type), or a func with an unsupported signature like func(int) error.","commonSituations":"Passing a typed nil (var h MyHandler = nil) that does not match any case; passing a handler with a subtly wrong signature (e.g. func(c *fiber.Ctx) when Ctx is an interface, or returning a non-error); forgetting to wrap an http.Handler; copy-paste leaving a placeholder value/zero struct in the variadic args.","solutions":["Check the offending argument's type (the panic prints it) and convert it to a supported handler signature — most simply fiber.Handler (func(Ctx) error).","If passing a typed-nil handler, replace it with a real handler or omit it; nil values short-circuit toFiberHandler.","Wrap net/http handlers with an explicit adapter or pass them directly only if their static type is exactly http.HandlerFunc/http.Handler/func(http.ResponseWriter,*http.Request)."],"exampleFix":"// before\nd.Use(\"/api\", 42)                       // int -> panic\nd.Use(\"/api\", func(c *fiber.Ctx) error{...}) // wrong: *Ctx vs interface Ctx\n// after\nd.Use(\"/api\", func(c fiber.Ctx) error{ return nil })","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// isUseArg reports whether v is accepted by domainRouter.Use / Group.Use / App.Use.\nfunc isUseArg(v any) bool {\n    switch v.(type) {\n    case string, []string, *fiber.App:\n        return true\n    case fiber.Handler, func(fiber.Ctx),\n        func(fiber.Req, fiber.Res) error, func(fiber.Req, fiber.Res),\n        func(fiber.Req, fiber.Res, func() error) error, func(fiber.Req, fiber.Res, func() error),\n        func(fiber.Req, fiber.Res, func()) error, func(fiber.Req, fiber.Res, func()),\n        func(fiber.Req, fiber.Res, func(error)), func(fiber.Req, fiber.Res, func(error)) error,\n        func(fiber.Req, fiber.Res, func(error) error), func(fiber.Req, fiber.Res, func(error) error) error,\n        http.HandlerFunc, http.Handler, func(http.ResponseWriter, *http.Request),\n        fasthttp.RequestHandler, func(*fasthttp.RequestCtx) error:\n        return true\n    }\n    return false\n}\n\nfor _, a := range args {\n    if !isUseArg(a) {\n        return fmt.Errorf(\"unsupported Use arg %T\", a)\n    }\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"domain Use arg rejected: %v\", r)\n    }\n}()\nd.Use(args...)","preventionTips":["Standardize on fiber.Handler (func(Ctx) error) for all middleware/handlers.","Never pass typed-nil handlers; check non-nil before appending.","Avoid wrapping handlers in custom struct types that obscure the underlying func signature."],"tags":["routing","domain","handler","type-mismatch","startup"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}