go-delve/delve · error
wrong number of arguments
Error message
wrong number of arguments
What it means
The read_file Starlark builtin in Delve's terminal scripting layer accepts exactly one positional argument (the file path). When a Starlark init script calls read_file with zero arguments or more than one, the builtin returns this error, decorated with the Starlark call stack via decorateError. It exists to enforce the documented '(Path)' signature before any file I/O is attempted.
Source
Thrown at pkg/terminal/starbind/starlark.go:107
argstrs := make([]string, len(args))
for i := range args {
a, ok := args[i].(starlark.String)
if !ok {
return nil, errors.New("argument of dlv_command is not a string")
}
argstrs[i] = string(a)
}
err := env.ctx.CallCommand(strings.Join(argstrs, " "))
if err != nil && strings.Contains(err.Error(), " has exited with status ") {
return env.interfaceToStarlarkValue(err), nil
}
return starlark.None, decorateError(thread, err)
})
builtindoc(dlvCommandBuiltinName, "(Command)", "interrupts, continues and steps through the program.")
env.env[readFileBuiltinName] = starlark.NewBuiltin(readFileBuiltinName, func(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
if len(args) != 1 {
return nil, decorateError(thread, errors.New("wrong number of arguments"))
}
path, ok := args[0].(starlark.String)
if !ok {
return nil, decorateError(thread, errors.New("argument of read_file was not a string"))
}
buf, err := os.ReadFile(string(path))
if err != nil {
return nil, decorateError(thread, err)
}
return starlark.String(string(buf)), nil
})
builtindoc(readFileBuiltinName, "(Path)", "reads a file.")
env.env[appendFileBuiltinName] = starlark.NewBuiltin(appendFileBuiltinName, func(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
if len(args) != 2 {
return nil, decorateError(thread, errors.New("wrong number of arguments"))
}
path, ok := args[0].(starlark.String)View on GitHub (pinned to a23773e6c3)
Solutions
- Call read_file with exactly one string argument: read_file("/path/to/file")
- If you need to combine multiple paths, build a single string first with the + operator or str() concatenation
- Run `dlv help` or check the builtins listing (`help()` in the terminal) to confirm the documented signature '(Path)'
Example fix
// before (in .dlv/init Starlark script)
contents = read_file("/tmp/bps.txt", "r")
// after
contents = read_file("/tmp/bps.txt") Defensive patterns
Strategy: validation
Validate before calling
// in Starlark before calling
if len(args) != 1:
fail("read_file requires exactly one path argument")
path = args[0]
if type(path) != "string":
fail("read_file path must be a string") Type guard
def is_str(v):
return type(v) == "string"
# usage
if is_str(p):
contents = read_file(p) Prevention
- Match the documented signature '(Path)' exactly - one string argument
- Concatenate path pieces into a single string before calling
- Test init scripts with `dlv --init script.init` on a trivial session first
When it happens
Trigger: Calling read_file() with no arguments, read_file(a, b) with two or more arguments, or when extra positional arguments are accidentally passed (e.g. leftover arguments from a variable expansion) inside a Starlark init script executed by dlv.
Common situations: Users write ~/.dlv/init scripts or automation scripts that read config/state files; a typo like read_file(path, 0) or refactoring that leaves a second argument behind triggers this. It also appears when porting scripts from Python-style helpers that accept optional arguments.
Related errors
- value not loaded
- not hashable
- cycle in load graph
- argument of dlv_command is not a string
- argument of read_file was not a string
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/42b4353ee25ae8d7.
Report an issue: GitHub.