{"record":{"id":"9507c34556d79dc3","repo":"go-delve/delve","slug":"wrong-number-of-arguments-for-s","errorCode":null,"errorMessage":"wrong number of arguments for %s","messagePattern":"wrong number of arguments for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/starlark.go","lineNumber":363,"sourceCode":"\t}, allowedPrefixes)\n\treturn nil\n}\n\n// callMain calls the main function in globals, if one was defined.\nfunc (env *Env) callMain(thread *starlark.Thread, globals starlark.StringDict, mainFnName string, args []any) (starlark.Value, error) {\n\tif mainFnName == \"\" {\n\t\treturn starlark.None, nil\n\t}\n\tmainval := globals[mainFnName]\n\tif mainval == nil {\n\t\treturn starlark.None, nil\n\t}\n\tmainfn, ok := mainval.(*starlark.Function)\n\tif !ok {\n\t\treturn starlark.None, fmt.Errorf(\"%s is not a function\", mainFnName)\n\t}\n\tif mainfn.NumParams() != len(args) {\n\t\treturn starlark.None, fmt.Errorf(\"wrong number of arguments for %s\", mainFnName)\n\t}\n\targtuple := make(starlark.Tuple, len(args))\n\tfor i := range args {\n\t\targtuple[i] = env.interfaceToStarlarkValue(args[i])\n\t}\n\treturn starlark.Call(thread, mainfn, argtuple, nil)\n}\n\nfunc isCancelled(thread *starlark.Thread) error {\n\tif ctx, ok := thread.Local(dlvContextName).(context.Context); ok {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\t}\n\treturn nil\n}","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/starlark.go#L345-L381","documentation":"callMain enforces that the script's `main` function's parameter count exactly matches the number of arguments supplied by the host (Execute). If `mainfn.NumParams()` differs from len(args), the call is rejected with this error before invocation.","triggerScenarios":"`Execute`/`callMain` invoked with a specific argument list (e.g. 0 or 1 args) against a script whose `main` declares a different number of parameters, e.g. `def main(a, b): ...` while the host passes one argument.","commonSituations":"Scripts written for a different delve command/entrypoint convention (some host code calls main with no args, others with script args), or after editing `main` to add a parameter.","solutions":["Change `main` to accept exactly the number of arguments the host passes (check your delve invocation, e.g. `dlv ... -- --scriptarg`).","Use a default/variadic-compatible signature if your starlark version supports it, or accept one args param.","Verify with the docs of the specific delve scripting entrypoint how many args are passed."],"exampleFix":"// before\n// host calls main with 1 argument\ndef main():\n    pass\n// after\ndef main(arg):\n    pass","handlingStrategy":"validation","validationCode":"# starlark: check your main signature matches host args\ndef main(arg):  # host passes exactly 1 argument\n    pass","typeGuard":null,"tryCatchPattern":"err := env.Execute(script, args)\nif err != nil && strings.Contains(err.Error(), \"wrong number of arguments\") {\n    return fmt.Errorf(\"script main() must accept %d args: %w\", len(args), err)\n}","preventionTips":["Count parameters of main against the documented host call convention","Avoid changing main's arity when porting scripts","Document expected script args in a header comment"],"tags":["go","starlark","arity-mismatch","scripting"],"backgroundTag":"function-arity-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}