{"record":{"id":"f26bc465f7d835d4","repo":"charmbracelet/gum","slug":"failed-to-read-line-w","errorCode":null,"errorMessage":"failed to read line: %w","messagePattern":"failed to read line: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stdin/stdin.go","lineNumber":53,"sourceCode":"\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)\n\t\t}\n\t}\n\n\tfor !options.singleLine {\n\t\tr, _, err := reader.ReadRune()\n\t\tif err != nil && err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\t_, err = b.WriteRune(r)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to write rune: %w\", err)\n\t\t}\n\t}\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/internal/stdin/stdin.go#L35-L71","documentation":"Returned by internal/stdin.Read when bufio.Reader.ReadLine fails while reading a single line from stdin. The underlying I/O error is wrapped with %w. It indicates the read from the stdin pipe failed before any line could be returned.","triggerScenarios":"Calling Read with the singleLine option when ReadLine returns an error — e.g. stdin closed abruptly (EPIPE/EINVAL), an I/O error on the pipe, or a line exceeding bufio's buffer in problematic conditions.","commonSituations":"Upstream process in a pipeline exits and closes the pipe mid-read; stdin is a closed or invalid file descriptor in a detached daemon/subprocess context; running under environments that replace stdin with a broken descriptor.","solutions":["Inspect errors.Unwrap(err) for the specific syscall/IO cause","Ensure the upstream writer keeps the pipe open until your process finishes reading","Check that stdin is a valid readable descriptor when spawning programmatically","Retry reading or fall back to reading from a file if stdin is unreliable in your environment"],"exampleFix":"// before\nline, _ := stdin.Read(stdin.WithSingleLine())\n// after\nline, err := stdin.Read(stdin.WithSingleLine())\nif err != nil {\n    log.Fatalf(\"stdin read failed: %v\", errors.Unwrap(err))\n}","handlingStrategy":"try-catch","validationCode":"if hasPipedStdin() == false { return fmt.Errorf(\"stdin not available for line read\") }","typeGuard":"func isReadableFD(f *os.File) bool { fi, err := f.Stat(); return err == nil && fi.Mode()&os.ModeCharDevice == 0 }","tryCatchPattern":"line, err := stdin.Read(stdin.WithSingleLine())\nif err != nil {\n    return fmt.Errorf(\"line read failed: %w\", err)\n}","preventionTips":["Keep upstream pipe writers open until the read completes","Avoid spawning with closed/invalid stdin descriptors","Unwrap the error to identify the syscall cause"],"tags":["go","stdin","io","bufio"],"backgroundTag":"stdin-read-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}