{"record":{"id":"dea3f4b18a7ac57c","repo":"wavetermdev/waveterm","slug":"reading-file-w","errorCode":null,"errorMessage":"reading file: %w","messagePattern":"reading file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file.go","lineNumber":181,"sourceCode":"\tExample: \"  wsh file mv wsh://user@ec2/home/user/config.txt ./local-config.txt\\n  wsh file mv ./local-config.txt wsh://user@ec2/home/user/config.txt\",\n\tArgs:    cobra.ExactArgs(2),\n\tRunE:    activityWrap(\"file\", fileMvRun),\n\tPreRunE: preRunSetupRpcClient,\n}\n\nfunc fileCatRun(cmd *cobra.Command, args []string) error {\n\tpath, err := fixRelativePaths(args[0])\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfileData := wshrpc.FileData{\n\t\tInfo: &wshrpc.FileInfo{\n\t\t\tPath: path}}\n\n\terr = streamReadFromFile(cmd.Context(), fileData, os.Stdout)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc fileInfoRun(cmd *cobra.Command, args []string) error {\n\tpath, err := fixRelativePaths(args[0])\n\tif err != nil {\n\t\treturn err\n\t}\n\tfileData := wshrpc.FileData{\n\t\tInfo: &wshrpc.FileInfo{\n\t\t\tPath: path}}\n\n\tinfo, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\terr = convertNotFoundErr(err)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting file info: %w\", err)","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file.go#L163-L199","documentation":"fileCatRun wraps any error from streamReadFromFile with 'reading file:'. This is the top-level wrapper for `wsh file cat`; the underlying cause is one of the streamReadFromFile failures (no info, no route id, path parse error, stream start failure, or io.Copy failure).","triggerScenarios":"`wsh file cat <path>` where the underlying stream fails: invalid path URI, no RPC connection, remote file missing/unreadable, or interruption of the stream copy (ctx cancelled, connection reset).","commonSituations":"Catting a nonexistent remote file, running wsh outside a terminal with no RPC broker, network drop mid-transfer, hitting Ctrl-C partway (context cancelled).","solutions":["Read the wrapped cause: fix per the inner error (route id, path parse, or stream start).","Confirm the file exists remotely with `wsh file info <path>` first.","Re-run with a stable connection; avoid cancelling or killing the CLI mid-stream."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"info, err := wshclient.FileInfoCommand(RpcClient, &wshrpc.FileData{Info: &wshrpc.FileInfo{Path: path}}, &wshrpc.RpcOpts{Timeout: fileTimeout})\nif err != nil || info.NotFound {\n    return fmt.Errorf(\"cannot cat %q: missing or unreachable\", path)\n}","typeGuard":null,"tryCatchPattern":"if err := streamReadFromFile(cmd.Context(), fileData, os.Stdout); err != nil {\n    switch {\n    case strings.Contains(err.Error(), \"no route id\"):\n        // fix connection\n    case strings.Contains(err.Error(), \"parsing file path\"):\n        // fix URI\n    default:\n        // stream failure: retry or report\n    }\n    return fmt.Errorf(\"reading file: %w\", err)\n}","preventionTips":["Stat the file (wsh file info) before catting in scripts.","Verify the wsh:// URI and target host explicitly in automation.","Handle SIGINT/cancellation gracefully so partial streams fail cleanly."],"tags":["go","wsh","file-cat","streaming"],"backgroundTag":"file-read-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}