{"record":{"id":"e2c0abc53d66dfce","repo":"charmbracelet/gum","slug":"failed-to-write-w","errorCode":null,"errorMessage":"failed to write: %w","messagePattern":"failed to write: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/stdin/stdin.go","lineNumber":57,"sourceCode":"\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\n\ts := strings.TrimSpace(b.String())\n\tif options.ansiStrip {\n\t\treturn ansi.Strip(s), nil\n\t}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/internal/stdin/stdin.go#L39-L75","documentation":"Returned by internal/stdin.Read when b.Write(line) fails after a successful ReadLine in singleLine mode. Writing to a strings.Builder essentially only fails on out-of-memory, so this error is rare and indicates the process cannot allocate memory to buffer the line.","triggerScenarios":"Calling Read with singleLine option where strings.Builder.Write returns an error — practically only under memory exhaustion in the Go runtime.","commonSituations":"Extremely constrained memory environments (containers with tight limits); a pathological single line consuming all available memory before the write fails.","solutions":["Increase the memory limit of the container/process running the command","Check for pathologically large input lines being piped in","Use strings.Builder's available-memory diagnostics (b.Cap()) if profiling allocation","Handle the error and abort gracefully rather than retrying the same read"],"exampleFix":"// before\nline, _ := stdin.Read(stdin.WithSingleLine())\n// after\nline, err := stdin.Read(stdin.WithSingleLine())\nif err != nil {\n    log.Fatalf(\"could not buffer line: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"// No practical pre-check; strings.Builder fails only on OOM.\n// Keep input lines bounded:\nif len(rawLine) > 1<<20 { return fmt.Errorf(\"line too large\") }","typeGuard":null,"tryCatchPattern":"line, err := stdin.Read(stdin.WithSingleLine())\nif err != nil {\n    return fmt.Errorf(\"buffer write failed (OOM?): %w\", err)\n}","preventionTips":["Bound input line sizes before processing","Ensure adequate container memory limits","Avoid retrying identical reads after OOM errors"],"tags":["go","memory","strings-builder","buffer"],"backgroundTag":"memory-allocation-failed","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}