charmbracelet/gum · error
failed to write col %d of selected row: %w
Error message
failed to write col %d of selected row: %w
What it means
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.
Source
Thrown at table/command.go:170
padding: []int{top, right, bottom, left},
}
tm, err := tea.NewProgram(
m,
tea.WithOutput(os.Stderr),
tea.WithContext(ctx),
).Run()
if err != nil {
return fmt.Errorf("failed to start tea program: %w", err)
}
if tm == nil {
return fmt.Errorf("failed to get selection")
}
m = tm.(model)
if o.ReturnColumn > 0 && o.ReturnColumn <= len(m.selected) {
if err = writer.Write([]string{m.selected[o.ReturnColumn-1]}); err != nil {
return fmt.Errorf("failed to write col %d of selected row: %w", o.ReturnColumn, err)
}
} else {
if err = writer.Write([]string(m.selected)); err != nil {
return fmt.Errorf("failed to write selected row: %w", err)
}
}
writer.Flush()
return nil
}
View on GitHub (pinned to 4d089f9550)
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
Example fix
// before gum table --return-column 1 | head -n 1 # broken pipe // after result=$(gum table --return-column 1); echo "$result" | head -n 1
Defensive patterns
Strategy: try-catch
Try / catch
sel=$(gum table --return-column 2) || { echo 'output failed' >&2; exit 1; }
printf '%s\n' "$sel" Prevention
- 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
When it happens
Trigger: `--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.
Common situations: `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.
Related errors
- failed to write selected row: %w
- unable to write output: %w
- stdin is empty
- failed to read line: %w
- failed to write to stdout: %w
AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31).
Data as JSON: /api/errors/a205d1e3c90a01c2.
Report an issue: GitHub.