gofiber/fiber · critical

use: invalid handler %v\n

Error message

use: invalid handler %v\n

What it means

Panicked by app.Use (app.go:1045) when a variadic argument to app.Use(...) is not a recognized type (not a string prefix, not a *App, not a []string of prefixes, and not a convertible handler). The panic uses reflect.TypeOf(arg) to show the actual type so you can identify which argument was invalid.

Source

Thrown at app.go:1045

// This method will match all HTTP verbs: GET, POST, PUT, HEAD etc...
func (app *App) Use(args ...any) Router {
	var prefix string
	var subApp *App
	var prefixes []string
	var handlers []Handler

	for i := range args {
		switch arg := args[i].(type) {
		case string:
			prefix = arg
		case *App:
			subApp = arg
		case []string:
			prefixes = arg
		default:
			handler, ok := toFiberHandler(arg)
			if !ok {
				panic(fmt.Sprintf("use: invalid handler %v\n", reflect.TypeOf(arg)))
			}
			handlers = append(handlers, handler)
		}
	}

	if len(prefixes) == 0 {
		prefixes = append(prefixes, prefix)
	}

	for _, prefix := range prefixes {
		if subApp != nil {
			return app.mount(prefix, subApp)
		}

		app.register([]string{methodUse}, prefix, nil, handlers...)
	}

	return app

View on GitHub (pinned to 9a4c7e57fe)

Solutions

  1. Read the panic: it prints the Go type of the bad argument — locate that argument in your app.Use call.
  2. Ensure every non-prefix argument is a supported handler signature (see error 236).
  3. Split prefix strings from handlers; app.Use("/api", handler1, handler2).
  4. Add explicit type checks or use fiber.Handler to keep signatures correct.

Example fix

// before: passing a wrong type
app.Use("/api", myConfig)

// after: only prefixes and handlers
app.Use("/api", authMiddleware, logMiddleware)
Defensive patterns

Strategy: type-guard

Type guard

func isUseArg(a any) bool {
    switch a.(type) {
    case string, []string, *fiber.App:
        return true
    default:
        return isFiberHandler(a)
    }
}

Prevention

When it happens

Trigger: Calling app.Use with an unsupported argument type — e.g. app.Use(123), app.Use(someStruct), app.Use(func() {}) — or a method-value/interface whose signature is not in toFiberHandler's supported list. The default branch of the type switch (app.go:1042-1048) fires.

Common situations: Passing a non-handler middleware by mistake, a refactor that changed Use call sites, mixing up Use (which takes prefixes+handlers) with route methods, or passing an untyped nil wrapped in an interface.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/a80799cd5a1d862b.json. Report an issue: GitHub.