{"record":{"id":"38c08d07816e78be","repo":"gofiber/fiber","slug":"format-at-least-one-handler-is-required-but-none","errorCode":null,"errorMessage":"format: at least one handler is required, but none were set","messagePattern":"format: at least one handler is required, but none were set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"error.go","lineNumber":61,"sourceCode":"\t// ErrRangeUnsupported is returned for a Range header whose range unit is\n\t// not \"bytes\". RFC 9110 Section 14.2 requires an origin server to IGNORE\n\t// a Range header field with a range unit it does not understand, so\n\t// callers receiving this error should serve the full representation\n\t// instead of returning an error response. It still carries a\n\t// 400 Bad Request status as a safety net, so blind propagation does not\n\t// surface as a 500.\n\tErrRangeUnsupported   = NewError(StatusBadRequest, \"range: unsupported range unit\")\n\tErrRangeTooLarge      = NewError(StatusRequestedRangeNotSatisfiable, \"range: too many ranges\")\n\tErrRangeUnsatisfiable = errors.New(\"range: unsatisfiable range\")\n)\n\n// Binder errors\nvar ErrCustomBinderNotFound = errors.New(\"binder: custom binder not found, please be sure to enter the right name\")\n\n// Format errors\nvar (\n\t// ErrNoHandlers is returned when c.Format is called with no arguments.\n\tErrNoHandlers = errors.New(\"format: at least one handler is required, but none were set\")\n)\n\n// gofiber/schema errors\ntype (\n\t// ConversionError Conversion error exposes the internal schema.ConversionError for public use.\n\tConversionError = schema.ConversionError\n\t// UnknownKeyError error exposes the internal schema.UnknownKeyError for public use.\n\tUnknownKeyError = schema.UnknownKeyError\n\t// EmptyFieldError error exposes the internal schema.EmptyFieldError for public use.\n\tEmptyFieldError = schema.EmptyFieldError\n\t// MultiError error exposes the internal schema.MultiError for public use.\n\tMultiError = schema.MultiError\n)\n\n// encoding/json errors\ntype (\n\t// InvalidUnmarshalError describes an invalid argument passed to Unmarshal.\n\t// (The argument to Unmarshal must be a non-nil pointer.)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/error.go#L43-L79","documentation":"ErrNoHandlers is returned by DefaultRes.Format (res.go:436) when c.Format is called with zero ResFmt arguments. Format performs content negotiation on the Accept header and must have at least one handler to dispatch; an empty call is a programmer error. Note that Format lives on DefaultRes (the response side), not on a context-level helper.","triggerScenarios":"Calling c.Format() with no variadic arguments, for example when a slice of ResFmt is empty and splatted in (c.Format(handlers...) with len(handlers)==0). res.go:434-437 trips the guard immediately.","commonSituations":"Building the handlers list dynamically and not guarding the empty case; refactoring a switch into Format() and forgetting to populate the variants; spreading a slice without a length check.","solutions":["Guard the call: if len(handlers) > 0 { return c.Format(handlers...) } and handle the empty case explicitly.","Always pass at least one ResFmt, including a default MediaType:\"default\" handler as the fallback.","If you only need a single content type, use c.Set(HeaderContentType, ...) and c.Send instead."],"exampleFix":"// before\nreturn c.Format(handlers...)\n// after\nif len(handlers) == 0 {\n    return c.Status(fiber.StatusNotAcceptable).SendString(\"no handlers\")\n}\nreturn c.Format(handlers...)","handlingStrategy":"validation","validationCode":"// Guard Format against empty handlers so the call never reaches the\n// library precondition check.\nfunc negotiate(c fiber.Ctx, handlers []fiber.ResFmt) error {\n    if len(handlers) == 0 {\n        return c.Status(fiber.StatusNotAcceptable).SendString(\"no handlers\")\n    }\n    return c.Format(handlers...)\n}","typeGuard":null,"tryCatchPattern":"if err := c.Format(handlers...); err != nil {\n    if errors.Is(err, fiber.ErrNoHandlers) {\n        return c.Status(fiber.StatusNotAcceptable).SendString(\"no handlers\")\n    }\n    return err\n}","preventionTips":["Always pass at least one ResFmt, including a default MediaType:\"default\" fallback.","When building handlers dynamically, guard the empty case before calling Format.","For a single content type, use c.Set(HeaderContentType, ...) and c.Send instead."],"tags":["format","content-negotiation","response","programmer-error"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}