charmbracelet/gum · error

failed to write col of selected row

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.

Solutions

  1. Ensure the process consuming gum's stdout keeps the pipe open long enough
  2. Avoid piping into commands like `head` that close stdin early (use full output or buffering)
  3. Check the output destination (file/disk) is writable and has space
  4. 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

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


AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31). Data as JSON: /api/errors/a205d1e3c90a01c2. Report an issue: GitHub.

Appendix: 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)