go-delve/delve · error
wrong number of arguments for %s
Error message
wrong number of arguments for %s
What it means
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.
Source
Thrown at pkg/terminal/starbind/starlark.go:363
}, allowedPrefixes)
return nil
}
// callMain calls the main function in globals, if one was defined.
func (env *Env) callMain(thread *starlark.Thread, globals starlark.StringDict, mainFnName string, args []any) (starlark.Value, error) {
if mainFnName == "" {
return starlark.None, nil
}
mainval := globals[mainFnName]
if mainval == nil {
return starlark.None, nil
}
mainfn, ok := mainval.(*starlark.Function)
if !ok {
return starlark.None, fmt.Errorf("%s is not a function", mainFnName)
}
if mainfn.NumParams() != len(args) {
return starlark.None, fmt.Errorf("wrong number of arguments for %s", mainFnName)
}
argtuple := make(starlark.Tuple, len(args))
for i := range args {
argtuple[i] = env.interfaceToStarlarkValue(args[i])
}
return starlark.Call(thread, mainfn, argtuple, nil)
}
func isCancelled(thread *starlark.Thread) error {
if ctx, ok := thread.Local(dlvContextName).(context.Context); ok {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
}
return nil
}View on GitHub (pinned to a23773e6c3)
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.
Example fix
// before
// host calls main with 1 argument
def main():
pass
// after
def main(arg):
pass Defensive patterns
Strategy: validation
Validate before calling
# starlark: check your main signature matches host args
def main(arg): # host passes exactly 1 argument
pass Try / catch
err := env.Execute(script, args)
if err != nil && strings.Contains(err.Error(), "wrong number of arguments") {
return fmt.Errorf("script main() must accept %d args: %w", len(args), err)
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- panic executing starlark script: %v
- %s is not a function
- value not loaded
- not hashable
- cycle in load graph
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/9507c34556d79dc3.
Report an issue: GitHub.