wavetermdev/waveterm · error
reading stdin: %w
Error message
reading stdin: %w
What it means
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'.
Source
Thrown at cmd/wsh/cmd/wshcmd-debugterm.go:62
rootCmd.AddCommand(debugTermCmd)
debugTermCmd.Flags().Int64Var(&debugTermSize, "size", 1000, "number of terminal bytes to read")
debugTermCmd.Flags().StringVar(&debugTermMode, "mode", DebugTermModeHex, "output mode: hex or decode")
debugTermCmd.Flags().BoolVar(&debugTermStdin, "stdin", false, "read input from stdin instead of rpc call")
debugTermCmd.Flags().StringVar(&debugTermInput, "input", "", "read input from file instead of rpc call")
}
func debugTermRun(cmd *cobra.Command, args []string) (rtnErr error) {
defer func() {
sendActivity("debugterm", rtnErr == nil)
}()
mode, err := getDebugTermMode()
if err != nil {
return err
}
if debugTermStdin {
stdinData, err := io.ReadAll(WrappedStdin)
if err != nil {
return fmt.Errorf("reading stdin: %w", err)
}
termData, err := parseDebugTermStdinData(stdinData)
if err != nil {
return err
}
if mode == DebugTermModeDecode {
WriteStdout("%s", formatDebugTermDecode(termData))
} else {
WriteStdout("%s", formatDebugTermHex(termData))
}
return nil
}
if debugTermInput != "" {
fileData, err := os.ReadFile(debugTermInput)
if err != nil {
return fmt.Errorf("reading input file: %w", err)
}
termData, err := parseDebugTermStdinData(fileData)View on GitHub (pinned to a4447c1563)
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
Example fix
// before flaky-producer | wsh debugterm --stdin --decode // after flaky-producer > /tmp/capture.bin && wsh debugterm --input /tmp/capture.bin --decode
Defensive patterns
Strategy: try-catch
Validate before calling
// verify the pipe producer succeeded and data is non-empty first producer && [ -s capture.bin ] && cat capture.bin | wsh debugterm --stdin
Try / catch
stdinData, err := io.ReadAll(WrappedStdin)
if err != nil {
return fmt.Errorf("reading stdin: %w — check the upstream pipe producer exited cleanly", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- reading from stdin: %w
- failed to read JWT token from stdin: %w
- stdin (-) can only be used once
- reading input file: %w
- reading terminal output: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/3a851ddbf5905be4.
Report an issue: GitHub.