{"record":{"id":"7d0b55fb42d7cf3f","repo":"wavetermdev/waveterm","slug":"creating-file-w","errorCode":null,"errorMessage":"creating file: %w","messagePattern":"creating file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file-util.go","lineNumber":37,"sourceCode":")\n\nfunc convertNotFoundErr(err error) error {\n\tif err == nil {\n\t\treturn nil\n\t}\n\tif strings.HasPrefix(err.Error(), \"NOTFOUND:\") {\n\t\treturn fs.ErrNotExist\n\t}\n\treturn err\n}\n\nfunc ensureFile(fileData wshrpc.FileData) (*wshrpc.FileInfo, error) {\n\tinfo, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\terr = convertNotFoundErr(err)\n\tif err == fs.ErrNotExist {\n\t\terr = wshclient.FileCreateCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating file: %w\", err)\n\t\t}\n\t\tinfo, err = wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"getting file info: %w\", err)\n\t\t}\n\t\treturn info, err\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting file info: %w\", err)\n\t}\n\treturn info, nil\n}\n\nfunc streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {\n\t// First truncate the file with an empty write\n\temptyWrite := fileData\n\temptyWrite.Data64 = \"\"\n\terr := wshclient.FileWriteCommand(RpcClient, emptyWrite, &wshrpc.RpcOpts{Timeout: fileTimeout})","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file-util.go#L19-L55","documentation":"ensureFile first checks whether the target file exists via FileInfoCommand; if it reports not-found (fs.ErrNotExist), it attempts to create it with FileCreateCommand. This error wraps a failure of that create RPC — the file was absent AND could not be created.","triggerScenarios":"`wsh append <file>` (fileAppendRun) on a path whose FileInfoCommand returned NOTFOUND, and then FileCreateCommand fails: invalid path, permission denied on the remote, parent directory missing, or read-only filesystem.","commonSituations":"Appending to a file in a directory that does not exist remotely; no write permission for the connecting user; typo in the path; trying to create a file on a connection that is offline.","solutions":["Create the parent directory first (e.g. `wsh mkdir` or manually) and re-run the append.","Check write permissions on the target directory for your user on the target host.","Verify the file path/URI is correct and the remote connection is up (`wsh connection check`).","Create the file manually (touch) before running the append command."],"exampleFix":"// before\nwsh append /no/such/dir/log.txt\n// after\nwsh mkdir /no/such/dir && wsh append /no/such/dir/log.txt","handlingStrategy":"try-catch","validationCode":"parentDir := filepath.Dir(path)\nif info, err := wshclient.FileInfoCommand(RpcClient, wshrpc.FileData{Info: &wshrpc.FileInfo{Path: parentDir}}, &wshrpc.RpcOpts{Timeout: fileTimeout}); err != nil {\n    return fmt.Errorf(\"parent directory missing or unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"info, err := ensureFile(fileData)\nif err != nil && strings.Contains(err.Error(), \"creating file\") {\n    // handle: create parent dir, fix permissions, then retry\n}","preventionTips":["Create parent directories before appending to new paths","Verify write permissions on the target host","Double-check the file path/URI for typos"],"tags":["filesystem","rpc","permissions"],"backgroundTag":"file-create-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}