{"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":"exception","errorClass":"ErrNoHandlers","httpStatus":null,"severity":"error","filePath":"error.go","lineNumber":56,"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":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/error.go#L38-L74","documentation":"ErrNoHandlers (error.go:56) is returned by DefaultRes.Format (res.go:432) when c.Format() is called with zero ResFmt arguments. Format performs content negotiation by selecting among the provided handlers; with none there is nothing to negotiate, so it refuses rather than silently doing nothing.","triggerScenarios":"Calling c.Format() with no arguments, or passing a variadic slice that is nil/empty, e.g. c.Format(handlers...) where handlers was never populated. Also when a builder assembles the handler list conditionally and the list ends up empty.","commonSituations":"Building content-negotiation handlers from configuration that yields none, or copy-pasting a Format call and forgetting to add the handlers.","solutions":["Always pass at least one ResFmt, e.g. c.Format(fiber.ResFmt{MediaType: \"application/json\", Handler: writeJSON}).","When building the slice dynamically, fall back to a default handler if the list is empty.","Guard the call site: if len(handlers) == 0 return your own error before calling Format."],"exampleFix":"// before\nc.Format() // no handlers\n\n// after\nc.Format(\n    fiber.ResFmt{MediaType: \"application/json\", Handler: func(c fiber.Ctx) error { return c.JSON(data) }},\n    fiber.ResFmt{MediaType: \"text/html\", Handler: func(c fiber.Ctx) error { return c.SendString(html) }},\n)","handlingStrategy":"validation","validationCode":"// Ensure at least one handler before calling Format.\nif len(handlers) == 0 {\n    handlers = []fiber.ResFmt{{MediaType: \"default\", Handler: writeDefault}}\n}\nc.Format(handlers...)","typeGuard":null,"tryCatchPattern":"if err := c.Format(handlers...); err != nil {\n    if errors.Is(err, fiber.ErrNoHandlers) {\n        return fiber.NewError(fiber.StatusInternalServerError, \"no format handlers configured\")\n    }\n    return err\n}","preventionTips":["Always pass at least one ResFmt to Format.","When building handlers dynamically, default to a fallback handler for an empty list.","Guard the call site with a length check before invoking Format."],"tags":["response","content-negotiation","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}