{"record":{"id":"d52ff19a6f7fdd8a","repo":"wavetermdev/waveterm","slug":"reading-input-w-d52ff1","errorCode":null,"errorMessage":"reading input: %w","messagePattern":"reading input: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file.go","lineNumber":253,"sourceCode":"\t\treturn fmt.Errorf(\"removing file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc fileWriteRun(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\tlimitReader := io.LimitReader(WrappedStdin, MaxFileSize+1)\n\tdata, err := io.ReadAll(limitReader)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading input: %w\", err)\n\t}\n\tif len(data) > MaxFileSize {\n\t\treturn fmt.Errorf(\"input exceeds maximum file size of %d bytes\", MaxFileSize)\n\t}\n\tfileData.Data64 = base64.StdEncoding.EncodeToString(data)\n\terr = wshclient.FileWriteCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"writing file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc fileAppendRun(cmd *cobra.Command, args []string) error {\n\tpath, err := fixRelativePaths(args[0])\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file.go#L235-L271","documentation":"fileWriteRun reads the data to write from stdin via io.LimitReader over WrappedStdin; if the read itself fails the error is wrapped with 'reading input:'. This is an I/O failure on the local stdin pipe, not a remote write failure.","triggerScenarios":"`wsh file write <path>` (or `wsh file write <path> < input`) where the stdin pipe errors: broken pipe from the producing process, stdin closed prematurely, or aWrappedStdin wrapper (e.g. a logging/tapping writer) fails mid-read.","commonSituations":"Piping from a command that crashed halfway (producer killed), running without supplying stdin so the wrapper errors, disk/terminal I/O issues on the local machine.","solutions":["Re-run the command and confirm the producing side of the pipe completed successfully (check its exit status).","Ensure stdin is actually connected (pipe a file: `wsh file write p < data.bin`).","Bypass custom stdin wrappers in a local build if WrappedStdin is misbehaving.","Verify input integrity (e.g. checksum) and retry the transfer."],"exampleFix":"// before\nsomecmd | wsh file write out.bin   # somecmd crashed mid-stream\n// after\nsomecmd > tmp.bin && wsh file write out.bin < tmp.bin","handlingStrategy":"validation","validationCode":"// verify the producer succeeded before piping\ndata, err := io.ReadAll(io.LimitReader(WrappedStdin, MaxFileSize+1))\nif err != nil {\n    return fmt.Errorf(\"stdin unavailable: %w\", err)\n}\nif len(data) == 0 {\n    return fmt.Errorf(\"no input received on stdin\")\n}","typeGuard":null,"tryCatchPattern":"data, err := io.ReadAll(limitReader)\nif err != nil {\n    if errors.Is(err, syscall.EPIPE) {\n        // producer closed the pipe early — check producer exit status\n    }\n    return fmt.Errorf(\"reading input: %w\", err)\n}","preventionTips":["Check the exit code of any command piped into `wsh file write`.","Stage data to a temp file and redirect it rather than relying on live pipes.","Confirm stdin is attached when running non-interactively (no TTY)."],"tags":["go","wsh","file-write","stdin","io"],"backgroundTag":"stdin-read-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}