{"record":{"id":"a205d1e3c90a01c2","repo":"charmbracelet/gum","slug":"failed-to-write-col-d-of-selected-row-w","errorCode":null,"errorMessage":"failed to write col %d of selected row: %w","messagePattern":"failed to write col (.+?) of selected row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"table/command.go","lineNumber":170,"sourceCode":"\t\tpadding:   []int{top, right, bottom, left},\n\t}\n\ttm, err := tea.NewProgram(\n\t\tm,\n\t\ttea.WithOutput(os.Stderr),\n\t\ttea.WithContext(ctx),\n\t).Run()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to start tea program: %w\", err)\n\t}\n\n\tif tm == nil {\n\t\treturn fmt.Errorf(\"failed to get selection\")\n\t}\n\n\tm = tm.(model)\n\tif o.ReturnColumn > 0 && o.ReturnColumn <= len(m.selected) {\n\t\tif err = writer.Write([]string{m.selected[o.ReturnColumn-1]}); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write col %d of selected row: %w\", o.ReturnColumn, err)\n\t\t}\n\t} else {\n\t\tif err = writer.Write([]string(m.selected)); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write selected row: %w\", err)\n\t\t}\n\t}\n\n\twriter.Flush()\n\n\treturn nil\n}\n","sourceCodeStart":152,"sourceCodeEnd":182,"githubUrl":"https://github.com/charmbracelet/gum/blob/4d089f95507708a71f64dacfe7ca513219dd5267/table/command.go#L152-L182","documentation":"After a successful selection, gum table failed to write the requested column of the chosen row to the output writer. The underlying writer error is wrapped with %w. This happens after the TUI has already run, so selection succeeded but output failed.","triggerScenarios":"`--return-column N` is set and within range, `writer.Write(...)` returns an error — typically a broken stdout pipe (e.g. piped into `head` which closed early) or a closed/corrupted output stream.","commonSituations":"`gum table --return-column 2 | head -n1` causing SIGPIPE-style broken pipe, output redirected to a full disk or closed file descriptor, scripting that closes the pipe early.","solutions":["Ensure the process consuming gum's stdout keeps the pipe open long enough","Avoid piping into commands like `head` that close stdin early (use full output or buffering)","Check the output destination (file/disk) is writable and has space","Handle the wrapped error cause shown by %w for the specific writer failure"],"exampleFix":"// before\ngum table --return-column 1 | head -n 1   # broken pipe\n// after\nresult=$(gum table --return-column 1); echo \"$result\" | head -n 1","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"sel=$(gum table --return-column 2) || { echo 'output failed' >&2; exit 1; }\nprintf '%s\\n' \"$sel\"","preventionTips":["Capture output into a variable instead of piping into head","Keep downstream consumers reading until gum exits","Ensure stdout destination is writable with sufficient disk space"],"tags":["output","pipe","io"],"backgroundTag":"broken-pipe-write","analyzedSha":"4d089f95507708a71f64dacfe7ca513219dd5267","analyzedAt":"2026-08-31T18:45:06.436Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}