kataras/iris · error

Passed argument is not a func(iris.Context) neither one

Error message

			Passed argument is not a func(iris.Context) neither one of these types:
			- http.Handler
			- func(w http.ResponseWriter, r *http.Request)
			- func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
			---------------------------------------------------------------------
			It seems to be a %T points to: %v

What it means

FromStd panics when the argument is not a func(iris.Context), http.Handler, func(http.ResponseWriter,*http.Request), or func(...,next http.HandlerFunc). The error message includes the actual type and value for diagnosis.

Source

Thrown at core/handlerconv/from_std.go:48

		return FromStd(http.HandlerFunc(h))
	case func(http.ResponseWriter, *http.Request, http.HandlerFunc):
		// handlerFunc(w,r, http.HandlerFunc)
		//
		return FromStdWithNext(h)
	case func(http.Handler) http.Handler:
		panic(fmt.Errorf(`
			Passed handler cannot be converted directly:
			- http.Handler(http.Handler)
			---------------------------------------------------------------------
			Please use the Application.WrapRouter method instead, example code:
			app := iris.New()
			// ...
			app.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {
			    httpThirdPartyHandler(router).ServeHTTP(w, r)
			})`))
	default:
		// No valid handler passed
		panic(fmt.Errorf(`
			Passed argument is not a func(iris.Context) neither one of these types:
			- http.Handler
			- func(w http.ResponseWriter, r *http.Request)
			- func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
			---------------------------------------------------------------------
			It seems to be a %T points to: %v`, handler, handler))
	}
}

// FromStdWithNext receives a standar handler - middleware form - and returns a
// compatible context.Handler wrapper.
func FromStdWithNext(h func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)) context.Handler {
	return func(ctx *context.Context) {
		next := func(w http.ResponseWriter, r *http.Request) {
			ctx.ResetRequest(r)
			ctx.Next()
		}

View on GitHub (pinned to 7bedaf55a0)

Solutions

  1. Pass one of the supported types: func(iris.Context), http.Handler, func(w,r), or func(w,r,next).
  2. If you have func(ctx *iris.Context) from old code, migrate it to func(ctx iris.Context) (new Context API).
  3. Ensure you pass the method/function value itself, not the result of calling it, and that it is not nil.
  4. Wrap the value in http.HandlerFunc(yourFunc) when its signature is almost right.

Example fix

// before
app.Handle("GET", "/", oldHandler) // func(*iris.Context) -> panic
// after
app.Handle("GET", "/", func(ctx iris.Context) { oldLogic(ctx) }) // or http.HandlerFunc
Defensive patterns

Strategy: type-guard

Validate before calling

switch h.(type) {
case func(iris.Context), http.Handler, func(http.ResponseWriter, *http.Request), func(http.ResponseWriter, *http.Request, http.HandlerFunc):
    // ok
default:
    return errors.New("unsupported handler type")
}

Type guard

func isConvertibleHandler(v interface{}) bool {
    switch v.(type) {
    case func(iris.Context), http.Handler,
        func(http.ResponseWriter, *http.Request),
        func(http.ResponseWriter, *http.Request, http.HandlerFunc):
        return true
    }
    return false
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if strings.Contains(fmt.Sprint(r), "not a func(iris.Context)") {
            log.Fatalf("bad handler type: %v", r)
        }
        panic(r)
    }
}()

Prevention

When it happens

Trigger: Passing an unsupported value to FromStd or iris handlers registration: e.g. a bare struct, a func() , func(ctx *iris.Context) (old signature), a non-callable value, or a method value with the wrong signature.

Common situations: Migrating from old iris versions where handlers took *iris.Context; passing nil handler; passing an interface holding the wrong concrete type; typos like handler.ServeHTTP instead of handler.

Related errors


AI-assisted analysis of kataras/iris@7bedaf55a0 (2026-08-30). Data as JSON: /api/errors/ce0c317b9694166c. Report an issue: GitHub.