{"record":{"id":"f7477e6894f86b9a","repo":"charmbracelet/gum","slug":"failed-to-write-rune-w","errorCode":null,"errorMessage":"failed to write rune: %w","messagePattern":"failed to write rune: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stdin/stdin.go","lineNumber":68,"sourceCode":"\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\n\ts := strings.TrimSpace(b.String())\n\tif options.ansiStrip {\n\t\treturn ansi.Strip(s), nil\n\t}\n\treturn s, nil\n}\n\n// IsEmpty returns whether stdin is empty.\nfunc IsEmpty() bool {\n\tstat, err := os.Stdin.Stat()\n\tif err != nil {\n\t\treturn true\n\t}\n\n\tif stat.Mode()&os.ModeNamedPipe == 0 && stat.Size() == 0 {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/internal/stdin/stdin.go#L50-L86","documentation":"Returned by internal/stdin.Read when b.WriteRune(r) fails while accumulating runes from stdin in multi-line (default) mode. Like the line variant, strings.Builder only fails on memory exhaustion, so this wraps an out-of-memory condition. The error is wrapped with %w.","triggerScenarios":"Calling Read in default (non-singleLine) mode where WriteRune returns an error — practically only when the runtime cannot allocate memory for the growing buffer.","commonSituations":"Piping an enormous stream into the tool in a memory-limited container; runaway upstream producer flooding stdin; low-memory hosts.","solutions":["Increase container/process memory limits","Bound the size of the input stream before piping (e.g. head -c)","Ensure the upstream producer terminates instead of streaming indefinitely","Process the stream incrementally in your own code instead of buffering all of stdin"],"exampleFix":"// before\ncat huge.log | gum pager\n// after\nhead -c 10000000 huge.log | gum pager  # bound the input size","handlingStrategy":"validation","validationCode":"info, _ := os.Stdin.Stat()\nif info.Size() > maxInputBytes { return fmt.Errorf(\"stdin input exceeds %d bytes\", maxInputBytes) }","typeGuard":"func inputWithinLimit(r io.Reader, max int64) bool {\n    n, _ := io.Copy(io.Discard, io.LimitReader(r, max+1))\n    return n <= max\n}","tryCatchPattern":"out, err := stdin.Read()\nif err != nil {\n    return fmt.Errorf(\"stdin buffer failed (OOM?): %w\", err)\n}","preventionTips":["Limit piped stream size (e.g. head -c)","Raise memory limits for large-input workloads","Ensure upstream producers terminate"],"tags":["go","memory","stdin","buffer"],"backgroundTag":"memory-allocation-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}