{"id":"78086661bb89631f","repo":"gofiber/fiber","slug":"s-invalid-handler-d-t-n","errorCode":null,"errorMessage":"%s: invalid handler #%d (%T)\\n","messagePattern":"(.+?): invalid handler #(.+?) \\(%T\\)\\\\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"adapter.go","lineNumber":275,"sourceCode":"\tadapted := fasthttpadaptor.NewFastHTTPHandler(handler)\n\n\treturn func(c Ctx) error {\n\t\tadapted(c.RequestCtx())\n\t\treturn nil\n\t}\n}\n\n// collectHandlers converts a slice of handler arguments to Fiber handlers.\n// The context string is used to provide informative panic messages when an\n// unsupported handler type is encountered.\nfunc collectHandlers(context string, args ...any) []Handler {\n\thandlers := make([]Handler, 0, len(args))\n\n\tfor i, arg := range args {\n\t\thandler, ok := toFiberHandler(arg)\n\n\t\tif !ok {\n\t\t\tpanic(fmt.Sprintf(\"%s: invalid handler #%d (%T)\\n\", context, i, arg))\n\t\t}\n\t\thandlers = append(handlers, handler)\n\t}\n\n\treturn handlers\n}\n","sourceCodeStart":257,"sourceCodeEnd":282,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/adapter.go#L257-L282","documentation":"Panicked by collectHandlers (adapter.go:275) when one of the handler arguments passed to a route registration (app.Get/Post/Add/etc.) cannot be converted to a Fiber Handler via toFiberHandler. The panic message includes the context (which API was called), the 0-based argument index, and the Go type (%T) of the offending argument, so you can pinpoint the bad handler.","triggerScenarios":"Passing a value to app.Get(path, X) where X is not one of the ~17 supported handler signatures (fiber.Handler, func(Ctx), Express-style funcs, net/http handlers, fasthttp handlers). E.g. passing a struct, an int, a func with the wrong signature, or a wrapped interface.","commonSituations":"Refactor changing a handler signature; passing a method value with wrong receiver type; typo'd import using a different Ctx type; passing middleware that returns the wrong type; copy-paste between frameworks.","solutions":["Check the panic message for the index and %T — the offending argument's type tells you what's wrong.","Ensure each handler matches a supported signature: func(fiber.Ctx) error is the canonical Fiber handler.","If wrapping handlers, return the exact signature Fiber expects.","Run go vet / staticcheck to catch signature mismatches at build time."],"exampleFix":"// before: wrong signature (no error return)\napp.Get(\"/\", func(c fiber.Ctx) {})\n\n// after: canonical Fiber handler\napp.Get(\"/\", func(c fiber.Ctx) error {\n    return c.SendString(\"ok\")\n})","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isFiberHandler(h any) bool {\n    switch h.(type) {\n    case fiber.Handler, func(fiber.Ctx),\n        func(fiber.Req, fiber.Res) error, func(fiber.Req, fiber.Res),\n        func(http.ResponseWriter, *http.Request), http.Handler, http.HandlerFunc,\n        fasthttp.RequestHandler, func(*fasthttp.RequestCtx) error:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Use the canonical func(fiber.Ctx) error signature for all handlers.","Run go vet to catch signature drift early.","When wrapping handlers, preserve the exact supported signature."],"tags":["routing","handlers","adapter","panic","type-mismatch"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}