{"record":{"id":"b574250ea14c5680","repo":"kataras/iris","slug":"invalid-number-of-arguments","errorCode":null,"errorMessage":"invalid number of arguments","messagePattern":"invalid number of arguments","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/errors/handlers.go","lineNumber":370,"sourceCode":"\n\t\treturn nil\n\t}\n}\n\nfunc bindResponse[T, R any, F ResponseFunc[T, R]](ctx *context.Context, fn F, fnInput ...T) (R, bool) {\n\tvar req T\n\tswitch len(fnInput) {\n\tcase 0:\n\t\tvar ok bool\n\t\treq, ok = ReadPayload[T](ctx)\n\t\tif !ok {\n\t\t\tvar resp R\n\t\t\treturn resp, false\n\t\t}\n\tcase 1:\n\t\treq = fnInput[0]\n\tdefault:\n\t\tpanic(\"invalid number of arguments\")\n\t}\n\n\tif !validateRequest(ctx, req) {\n\t\tvar resp R\n\t\treturn resp, false\n\t}\n\n\tresp, err := fn(ctx, req)\n\tif err == nil {\n\t\tif !validateResponse(ctx, req, &resp) {\n\t\t\treturn resp, false\n\t\t}\n\t}\n\n\treturn resp, !HandleError(ctx, err)\n}\n\n// OK handles a generic response and error from a service call and sends a JSON response to the client.","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/errors/handlers.go#L352-L388","documentation":"bindResponse inspects the number of input arguments returned by a handler and only supports 0 or 1; anything else panics with 'invalid number of arguments'. It's an internal arity check on handlers used by OK/Create/NoContentOrNotModified helpers.","triggerScenarios":"Registering a response handler function whose reflected invocation yields 2+ input arguments (e.g. func(ctx, req, extra)) through OK/Create/NoContentOrNotModified.","commonSituations":"Writing a handler with extra dependency parameters beyond the single request payload; copy-pasting handlers with additional arguments.","solutions":["Change the handler to accept at most one request argument (plus the implicit context handling the framework provides)","Bundle extra parameters into a single request struct","Use the generic Handle/other APIs that support more arguments if more are needed"],"exampleFix":"// before\nfunc(ctx, req Req, logger *log.Logger) Resp { ... }\n// after\nfunc(ctx, req Req) Resp { /* logger from ctx or package level */ }","handlingStrategy":"type-guard","validationCode":"// keep handler arity <= 1 input argument\nfunc validHandlerArity(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.NumIn() <= 1\n}","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Printf(\"bindResponse panic: %v\", r) } }()\nxerrors.OK(handler)","preventionTips":["Limit response handler signatures to zero or one request argument","Group extra dependencies into the request struct","Lint handler signatures during code review"],"tags":["go","panic","handler-signature","x-errors"],"backgroundTag":"invalid-handler-arity","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}