{"record":{"id":"fda20af17073d040","repo":"charmbracelet/gum","slug":"stdin-is-empty","errorCode":null,"errorMessage":"stdin is empty","messagePattern":"stdin is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stdin/stdin.go","lineNumber":39,"sourceCode":"\n// StripANSI optionally strips ansi sequences.\nfunc StripANSI(b bool) Option {\n\treturn func(o *options) {\n\t\to.ansiStrip = b\n\t}\n}\n\n// SingleLine reads a single line.\nfunc SingleLine(b bool) Option {\n\treturn func(o *options) {\n\t\to.singleLine = b\n\t}\n}\n\n// Read reads input from an stdin pipe.\nfunc Read(opts ...Option) (string, error) {\n\tif IsEmpty() {\n\t\treturn \"\", fmt.Errorf(\"stdin is empty\")\n\t}\n\n\toptions := options{}\n\tfor _, opt := range opts {\n\t\topt(&options)\n\t}\n\n\treader := bufio.NewReader(os.Stdin)\n\tvar b strings.Builder\n\n\tif options.singleLine {\n\t\tline, _, err := reader.ReadLine()\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to read line: %w\", err)\n\t\t}\n\t\t_, err = b.Write(line)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to write: %w\", err)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/internal/stdin/stdin.go#L21-L57","documentation":"Returned by internal/stdin.Read when IsEmpty() reports that the stdin pipe has no data available. The library requires piped/redirected stdin content and refuses to proceed with empty input rather than blocking or returning an empty string.","triggerScenarios":"Running the command in a terminal with nothing piped in (stdin is a TTY or an already-drained pipe), or piping an empty file/stream: e.g. `echo -n '' | gum pager` or invoking without `< file`.","commonSituations":"Forgetting to pipe input in scripts; running interactively where stdin is the TTY; a prior command in the pipeline produced no output (e.g. grep matched nothing).","solutions":["Pipe or redirect content into the command: `cat file | gum pager` or `gum pager < file`","Check the upstream command in the pipeline actually produces output before invoking","If programmatic, verify the reader/write end of the pipe is written and closed properly","Handle the error in your caller and fall back to a file argument instead of stdin"],"exampleFix":"// before\nout, _ := stdin.Read()  // fails when nothing is piped\n// after\nout, err := stdin.Read()\nif err != nil {\n    data, ferr := os.ReadFile(\"input.txt\")\n    if ferr == nil { out = string(data) }\n}","handlingStrategy":"validation","validationCode":"stat, _ := os.Stdin.Stat()\nif (stat.Mode() & os.ModeCharDevice) != 0 { return fmt.Errorf(\"no piped stdin; provide input\") }","typeGuard":"func hasPipedStdin() bool {\n    fi, err := os.Stdin.Stat()\n    return err == nil && (fi.Mode()&os.ModeCharDevice) == 0\n}","tryCatchPattern":"out, err := stdin.Read()\nif err != nil {\n    if err.Error() == \"stdin is empty\" {\n        return fmt.Errorf(\"please pipe input: cmd | gum pager\")\n    }\n    return err\n}","preventionTips":["Always pipe or redirect input when invoking commands that read stdin","Verify upstream pipeline stages produce output","Check stat.Mode() for TTY before expecting stdin data"],"tags":["go","stdin","io","empty-input"],"backgroundTag":"stdin-empty","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}