{"id":"e1e0746876d6937e","repo":"gofiber/fiber","slug":"use-invalid-handler-v","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/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/domain.go#L349-L385","documentation":"Panics from domain.go:367 inside domainRouter.Use when an argument is not a string (prefix), []string (prefixes), *App (sub-app to mount), or a value convertible to a fiber.Handler. Use on a domain-scoped router accepts the same polymorphic arg list as app.Use; anything else is a programmer error.","triggerScenarios":"app.Domain(\"api.example.com\").Use(123), .Use(someStruct{}), .Use(nil) of an unsupported type, or passing an int/float/bool argument. Also when a handler variable of the wrong function shape (e.g. func() with no Ctx arg) is passed and toFiberHandler returns ok=false.","commonSituations":"Passing a plain function with the wrong signature; passing a struct thinking it is a handler; copy-paste from a non-fiber framework; nil interface of unhandled type.","solutions":["Pass only fiber.Handler (func(c fiber.Ctx) error) or compatible functions, plus optional string/[]string prefixes or *App.","Wrap non-conforming functions: convert func() {} into func(c fiber.Ctx) error { ...; return nil }.","Double-check argument order - prefix strings must precede handlers."],"exampleFix":"// before\napi := app.Domain(\"api.example.com\")\napi.Use(func() { log.Println(\"hi\") }) // wrong signature\n\n// after\napi := app.Domain(\"api.example.com\")\napi.Use(func(c fiber.Ctx) error {\n    log.Println(\"hi\")\n    return c.Next()\n})","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// fiber exposes toFiberHandler internally; replicate the accepted shapes:\nfunc isValidUseArg(v any) bool {\n    switch v.(type) {\n    case string, []string, *fiber.App:\n        return true\n    }\n    // accept any func(fiber.Ctx) error\n    if reflect.TypeOf(v).Kind() == reflect.Func {\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Pass only fiber.Handler functions plus optional string/[]string prefixes or *App.","Double-check handler signatures match func(fiber.Ctx) error.","Keep prefix strings before handlers in the argument list."],"tags":["routing","domain","middleware","handler","panic"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}