go-delve/delve · error
first argument of append_file was not a string
Error message
first argument of append_file was not a string
What it means
append_file's first argument must be a starlark.String containing the file path. If args[0] is any other Starlark type (int, list, None, etc.), the builtin returns this error before calling os.OpenFile. The message explicitly says 'first argument' because the second argument may legitimately be non-string (it is converted with toBytes).
Source
Thrown at pkg/terminal/starbind/starlark.go:127
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)
if err != nil {
return nil, decorateError(thread, err)
}
defer f.Close()
_, err = f.Write(toBytes(args[1]))
return starlark.None, decorateError(thread, err)
})
builtindoc(appendFileBuiltinName, "(Path, Text)", "append text to the specified file.")
env.env[writeFileBuiltinName] = starlark.NewBuiltin(writeFileBuiltinName, 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 write_file was not a string"))View on GitHub (pinned to a23773e6c3)
Solutions
- Quote or stringify the path: append_file(str(path_value), text)
- Check the variable actually holds a string before the call: print(path)
- Build paths with string concatenation instead of containers: append_file("/tmp/" + name, text)
Example fix
// before parts = ["/tmp", "out.log"] append_file(parts, "line\n") // after path = "/tmp/out.log" append_file(path, "line\n")
Defensive patterns
Strategy: type-guard
Validate before calling
if type(path) != "string":
fail("append_file path must be a string: " + str(path))
append_file(path, text) Type guard
def as_path(v):
return v if type(v) == "string" else str(v)
# usage
append_file(as_path(raw_path), text) Prevention
- Verify path variables hold strings, not lists of components
- Join path components with '+' or a join helper before calling
- Guard against None from failed lookups before using a value as a path
When it happens
Trigger: Calling append_file with a non-string first argument, e.g. append_file(123, "data"), append_file(None, "data"), or passing a Path-like/list value produced elsewhere in the script.
Common situations: Scripts that build paths via string operations that accidentally yield a list or None (e.g. a failed split or lookup), or users passing a numeric constant instead of a quoted path.
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
- argument of read_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/e7bffc848f9a1e85.
Report an issue: GitHub.