gofiber/fiber · error

format: at least one handler is required, but none were set

Error message

format: at least one handler is required, but none were set

What it means

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.

Solutions

  1. Guard the call: if len(handlers) > 0 { return c.Format(handlers...) } and handle the empty case explicitly.
  2. Always pass at least one ResFmt, including a default MediaType:"default" handler as the fallback.
  3. If you only need a single content type, use c.Set(HeaderContentType, ...) and c.Send instead.

Example fix

// before
return c.Format(handlers...)
// after
if len(handlers) == 0 {
    return c.Status(fiber.StatusNotAcceptable).SendString("no handlers")
}
return c.Format(handlers...)
Defensive patterns

Strategy: validation

Validate before calling

// Guard Format against empty handlers so the call never reaches the
// library precondition check.
func negotiate(c fiber.Ctx, handlers []fiber.ResFmt) error {
    if len(handlers) == 0 {
        return c.Status(fiber.StatusNotAcceptable).SendString("no handlers")
    }
    return c.Format(handlers...)
}

Try / catch

if err := c.Format(handlers...); err != nil {
    if errors.Is(err, fiber.ErrNoHandlers) {
        return c.Status(fiber.StatusNotAcceptable).SendString("no handlers")
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/38c08d07816e78be. Report an issue: GitHub.

Appendix: source

Thrown at error.go:61

	// ErrRangeUnsupported is returned for a Range header whose range unit is
	// not "bytes". RFC 9110 Section 14.2 requires an origin server to IGNORE
	// a Range header field with a range unit it does not understand, so
	// callers receiving this error should serve the full representation
	// instead of returning an error response. It still carries a
	// 400 Bad Request status as a safety net, so blind propagation does not
	// surface as a 500.
	ErrRangeUnsupported   = NewError(StatusBadRequest, "range: unsupported range unit")
	ErrRangeTooLarge      = NewError(StatusRequestedRangeNotSatisfiable, "range: too many ranges")
	ErrRangeUnsatisfiable = errors.New("range: unsatisfiable range")
)

// Binder errors
var ErrCustomBinderNotFound = errors.New("binder: custom binder not found, please be sure to enter the right name")

// Format errors
var (
	// ErrNoHandlers is returned when c.Format is called with no arguments.
	ErrNoHandlers = errors.New("format: at least one handler is required, but none were set")
)

// gofiber/schema errors
type (
	// ConversionError Conversion error exposes the internal schema.ConversionError for public use.
	ConversionError = schema.ConversionError
	// UnknownKeyError error exposes the internal schema.UnknownKeyError for public use.
	UnknownKeyError = schema.UnknownKeyError
	// EmptyFieldError error exposes the internal schema.EmptyFieldError for public use.
	EmptyFieldError = schema.EmptyFieldError
	// MultiError error exposes the internal schema.MultiError for public use.
	MultiError = schema.MultiError
)

// encoding/json errors
type (
	// InvalidUnmarshalError describes an invalid argument passed to Unmarshal.
	// (The argument to Unmarshal must be a non-nil pointer.)

View on GitHub (pinned to a105acad6c)