{"record":{"id":"8a5fc5cf41bd9b1a","repo":"go-delve/delve","slug":"argument-of-read-file-was-not-a-string","errorCode":null,"errorMessage":"argument of read_file was not a string","messagePattern":"argument of read_file was not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/starlark.go","lineNumber":111,"sourceCode":"\t\t\t\treturn nil, errors.New(\"argument of dlv_command is not a string\")\n\t\t\t}\n\t\t\targstrs[i] = string(a)\n\t\t}\n\t\terr := env.ctx.CallCommand(strings.Join(argstrs, \" \"))\n\t\tif err != nil && strings.Contains(err.Error(), \" has exited with status \") {\n\t\t\treturn env.interfaceToStarlarkValue(err), nil\n\t\t}\n\t\treturn starlark.None, decorateError(thread, err)\n\t})\n\tbuiltindoc(dlvCommandBuiltinName, \"(Command)\", \"interrupts, continues and steps through the program.\")\n\n\tenv.env[readFileBuiltinName] = starlark.NewBuiltin(readFileBuiltinName, func(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {\n\t\tif len(args) != 1 {\n\t\t\treturn nil, decorateError(thread, errors.New(\"wrong number of arguments\"))\n\t\t}\n\t\tpath, ok := args[0].(starlark.String)\n\t\tif !ok {\n\t\t\treturn nil, decorateError(thread, errors.New(\"argument of read_file was not a string\"))\n\t\t}\n\t\tbuf, err := os.ReadFile(string(path))\n\t\tif err != nil {\n\t\t\treturn nil, decorateError(thread, err)\n\t\t}\n\t\treturn starlark.String(string(buf)), nil\n\t})\n\tbuiltindoc(readFileBuiltinName, \"(Path)\", \"reads a file.\")\n\n\tenv.env[appendFileBuiltinName] = starlark.NewBuiltin(appendFileBuiltinName, func(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {\n\t\tif len(args) != 2 {\n\t\t\treturn nil, decorateError(thread, errors.New(\"wrong number of arguments\"))\n\t\t}\n\t\tpath, ok := args[0].(starlark.String)\n\t\tif !ok {\n\t\t\treturn nil, decorateError(thread, errors.New(\"first argument of append_file was not a string\"))\n\t\t}\n\t\tf, err := os.OpenFile(string(path), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o640)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/starlark.go#L93-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npath = None\ncontents = read_file(path)\n\n// after\npath = \"/tmp/delve_state.txt\"\ncontents = read_file(path)","handlingStrategy":"type-guard","validationCode":"if type(p) != \"string\":\n    p = str(p)\ncontents = read_file(p)","typeGuard":"def ensure_string(v):\n    if type(v) == \"string\":\n        return v\n    return str(v)\n\n# usage\ncontents = read_file(ensure_string(maybe_path))","tryCatchPattern":null,"preventionTips":["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"],"tags":["starlark","scripting","type-error"],"backgroundTag":"wrong-argument-type","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}