{"record":{"id":"d6d1b5918c73b022","repo":"kataras/iris","slug":"invalid-arguments","errorCode":null,"errorMessage":"invalid arguments","messagePattern":"invalid arguments","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"context/context_func.go","lineNumber":11,"sourceCode":"package context\n\nimport (\n\t\"errors\"\n\t\"reflect\"\n\t\"sync\"\n)\n\n// ErrInvalidArgs fires when the `Context.CallFunc`\n// is called with invalid number of arguments.\nvar ErrInvalidArgs = errors.New(\"invalid arguments\")\n\n// Func represents a function registered by the Context.\n// See its `buildMeta` and `call` internal methods.\ntype Func struct {\n\tRegisterName    string // the name of which this function is registered, for information only.\n\tRaw             any    // the Raw function, can be used for custom casting.\n\tPersistenceArgs []any  // the persistence input arguments given on registration.\n\n\tonce sync.Once // guards build once, on first call.\n\t// Available after the first call.\n\tMeta *FuncMeta\n}\n\nfunc newFunc(name string, fn any, persistenceArgs ...any) *Func {\n\treturn &Func{\n\t\tRegisterName:    name,\n\t\tRaw:             fn,\n\t\tPersistenceArgs: persistenceArgs,","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context_func.go#L1-L29","documentation":"ErrInvalidArgs is returned by the internal Func.call method when a function registered via Context (Context.CallFunc / registered Func) is invoked with an invalid number of arguments, detected through reflection against the raw function's signature. The library throws it to fail fast on programming mistakes rather than panicking deep inside reflection.","triggerScenarios":"Calling ctx.CallFunc (or the registered function through Context) with fewer or more arguments than the wrapped function's signature declares; registering a variadic-mismatched or wrong-arity function and invoking it with an incompatible argument list; framework internals dispatching to a Func whose expected input count doesn't match what's provided.","commonSituations":"Refactoring a registered function's signature without updating all call sites; passing nil or zero arguments to a function that expects parameters; dynamic invocation from plugins/handlers building the argument slice at runtime; middleware calling framework-registered funcs with wrong payloads.","solutions":["Match the argument count to the registered function's signature: inspect the Func.Raw signature and supply exactly that many arguments.","Wrap the call with errors.Is(err, context.ErrInvalidArgs) and log the expected vs provided argument count.","If the count is dynamic, build the args slice from reflect.TypeOf(fn.Raw).NumIn() before calling.","Add a unit test that invokes every registered Func with its intended argument list to catch arity drift after refactors."],"exampleFix":"// before\nfn := app.Context().Func(\"handler\") // expects (ctx, arg1, arg2)\nerr := fn.Call(ctx)                  // missing args -> ErrInvalidArgs\n\n// after\nfn := app.Context().Func(\"handler\")\nif n := reflect.TypeOf(fn.Raw).NumIn(); n != len(args)+1 {\n    return fmt.Errorf(\"func %s: want %d args, got %d\", fn.RegisterName, n-1, len(args))\n}\nerr := fn.Call(ctx, args...)","handlingStrategy":"validation","validationCode":"want := reflect.TypeOf(fn.Raw).NumIn()\nif got := len(args) + 1 /* +ctx */; got != want {\n    return fmt.Errorf(\"%s: want %d args, got %d\", fn.RegisterName, want, got)\n}","typeGuard":"func isInvalidArgs(err error) bool {\n    return errors.Is(err, context.ErrInvalidArgs)\n}","tryCatchPattern":"if err := fn.Call(ctx, args...); err != nil {\n    if errors.Is(err, context.ErrInvalidArgs) {\n        // log expected vs provided arity and skip/abort the call\n        return nil\n    }\n    return err\n}","preventionTips":["Keep registered function signatures and call sites in sync; update all callers on signature changes.","Derive argument counts from reflect.TypeOf(fn.Raw).NumIn() instead of hardcoding.","Write a smoke test that calls each registered Func with its intended arguments.","Avoid dynamic arg construction without validating length before the call."],"tags":["reflection","arguments","programming-error","iris"],"backgroundTag":"invalid-arguments","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}