{"record":{"id":"3a851ddbf5905be4","repo":"wavetermdev/waveterm","slug":"reading-stdin-w","errorCode":null,"errorMessage":"reading stdin: %w","messagePattern":"reading stdin: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-debugterm.go","lineNumber":62,"sourceCode":"\trootCmd.AddCommand(debugTermCmd)\n\tdebugTermCmd.Flags().Int64Var(&debugTermSize, \"size\", 1000, \"number of terminal bytes to read\")\n\tdebugTermCmd.Flags().StringVar(&debugTermMode, \"mode\", DebugTermModeHex, \"output mode: hex or decode\")\n\tdebugTermCmd.Flags().BoolVar(&debugTermStdin, \"stdin\", false, \"read input from stdin instead of rpc call\")\n\tdebugTermCmd.Flags().StringVar(&debugTermInput, \"input\", \"\", \"read input from file instead of rpc call\")\n}\n\nfunc debugTermRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tdefer func() {\n\t\tsendActivity(\"debugterm\", rtnErr == nil)\n\t}()\n\tmode, err := getDebugTermMode()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif debugTermStdin {\n\t\tstdinData, err := io.ReadAll(WrappedStdin)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading stdin: %w\", err)\n\t\t}\n\t\ttermData, err := parseDebugTermStdinData(stdinData)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif mode == DebugTermModeDecode {\n\t\t\tWriteStdout(\"%s\", formatDebugTermDecode(termData))\n\t\t} else {\n\t\t\tWriteStdout(\"%s\", formatDebugTermHex(termData))\n\t\t}\n\t\treturn nil\n\t}\n\tif debugTermInput != \"\" {\n\t\tfileData, err := os.ReadFile(debugTermInput)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading input file: %w\", err)\n\t\t}\n\t\ttermData, err := parseDebugTermStdinData(fileData)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-debugterm.go#L44-L80","documentation":"With --stdin, debugTermRun reads all of standard input via io.ReadAll(WrappedStdin) before parsing it as terminal data. Any read failure (broken pipe, I/O error on the wrapped reader) is wrapped as 'reading stdin'.","triggerScenarios":"Piping into `wsh debugterm --stdin` when the upstream writer fails or closes the pipe abruptly; the wrapped stdin reader (pty-aware) hits an OS-level I/O error.","commonSituations":"A producer command crashed mid-pipe (e.g. `producer | wsh debugterm --stdin`); piping from a device that errors; attempting to feed binary data through a layer that mangles/closes the stream.","solutions":["Check the upstream command in the pipe completed successfully before debugterm","Re-run writing the data to a file and use --input instead of --stdin","Avoid intermediate filters (grep/sed) that may close the pipe early — use cat","Test with a small known-good file: cat data.bin | wsh debugterm --stdin"],"exampleFix":"// before\nflaky-producer | wsh debugterm --stdin --decode\n// after\nflaky-producer > /tmp/capture.bin && wsh debugterm --input /tmp/capture.bin --decode","handlingStrategy":"try-catch","validationCode":"// verify the pipe producer succeeded and data is non-empty first\nproducer && [ -s capture.bin ] && cat capture.bin | wsh debugterm --stdin","typeGuard":null,"tryCatchPattern":"stdinData, err := io.ReadAll(WrappedStdin)\nif err != nil {\n\treturn fmt.Errorf(\"reading stdin: %w — check the upstream pipe producer exited cleanly\", err)\n}","preventionTips":["Prefer --input <file> over --stdin for automation to avoid pipe fragility","Check upstream commands' exit codes with set -o pipefail","Avoid intermediate filters that can close the pipe early","Test the pipeline with a small known-good capture file"],"tags":["stdin","io","cli","debug"],"backgroundTag":"stdin-read-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}