go-delve/delve · error
argument of read_file was not a string
Error message
argument of read_file was not a string
What it means
read_file's sole argument must be a starlark.String path. If the first positional argument is any other Starlark value (int, list, None, bytes-like value, etc.), the builtin rejects it with this error before attempting os.ReadFile. This type check protects os.ReadFile from receiving a non-path value.
Source
Thrown at pkg/terminal/starbind/starlark.go:111
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)
if !ok {
return nil, decorateError(thread, errors.New("first argument of append_file was not a string"))
}
f, err := os.OpenFile(string(path), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o640)View on GitHub (pinned to a23773e6c3)
Solutions
- Ensure the argument is a quoted string or a str-typed variable: read_file("/tmp/log.txt")
- Convert values with str() before calling: read_file(str(my_value))
- Print or inspect the argument with print(type(x)) to confirm it is a string
Example fix
// before path = None contents = read_file(path) // after path = "/tmp/delve_state.txt" contents = read_file(path)
Defensive patterns
Strategy: type-guard
Validate before calling
if type(p) != "string":
p = str(p)
contents = read_file(p) Type guard
def ensure_string(v):
if type(v) == "string":
return v
return str(v)
# usage
contents = read_file(ensure_string(maybe_path)) Prevention
- Always build paths with string literals or str() conversion
- Check for None returns from earlier calls before using them as paths
- print(type(x)) when unsure of a value's type
When it happens
Trigger: Calling read_file with a non-string first argument, e.g. read_file(None), read_file(42), read_file(some_list), or passing the result of a function that returns a non-string value (such as a loaded Variable) as the path.
Common situations: Scripts that assume a variable holds a path string but it actually holds a parsed value, a None returned by an earlier failed call, or a numeric file descriptor. Also common when users confuse read_file with a generic file-open API expecting flags/modes.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- argument of dlv_command is not a string
- first argument of append_file was not a string
- first argument of write_file was not a string
- value not loaded
- not hashable
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/8a5fc5cf41bd9b1a.
Report an issue: GitHub.