{"record":{"id":"6ce6028e70b8c21b","repo":"wavetermdev/waveterm","slug":"getting-file-info-w-6ce602","errorCode":null,"errorMessage":"getting file info: %w","messagePattern":"getting file info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file-util.go","lineNumber":41,"sourceCode":"\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})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initializing file with empty write: %w\", err)\n\t}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file-util.go#L23-L59","documentation":"After successfully creating a missing file, ensureFile re-queries FileInfoCommand to fetch the new file's info. If that second RPC fails, the error is wrapped as \"getting file info\". It means the file was created but its metadata could not be read back.","triggerScenarios":"FileInfoCommand (post-create) fails due to RPC timeout (fileTimeout), transient connection drop between create and the info call, or a race where another process deleted the file right after creation.","commonSituations":"Slow or flaky remote connection exceeding the fileTimeout; concurrent jobs creating/deleting the same path; wsh server briefly restarting mid-command.","solutions":["Simply retry the append command — the create+info sequence is usually transient.","Increase the RPC timeout if operating over a high-latency connection.","Verify with `wsh ls` that the file now exists and is readable.","Check the wsh server logs on the remote host for the underlying RPC error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"info, err := ensureFile(fileData)\nif err != nil {\n    time.Sleep(500 * time.Millisecond)\n    info, err = ensureFile(fileData) // transient RPC failures usually clear\n}","preventionTips":["Avoid concurrent processes creating/deleting the same path","Increase fileTimeout on slow remote links","Ensure the wsh server is not restarting mid-command"],"tags":["filesystem","rpc","timeout"],"backgroundTag":"rpc-call-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}