charmbracelet/gum · error
failed to get selection
Error message
failed to get selection
What it means
The Bubble Tea program ran without error but returned a nil final model, so gum cannot extract the user's selection. This is a defensive check against a nil result from tea.Program.Run(). It means no selection state was produced at all.
Source
Thrown at table/command.go:164
m := model{
table: table,
showHelp: o.ShowHelp,
hideCount: o.HideCount,
help: help.New(),
keymap: defaultKeymap(),
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
- Re-run the command in a standard terminal; this is usually transient
- Update gum/Bubble Tea to the latest version to pick up runtime fixes
- Avoid sending abnormal signals (SIGKILL/SIGTSTP) during the table display
- Check for environment variables (TERM) that may break tea's runtime
Defensive patterns
Strategy: retry
Try / catch
for i in 1 2 3; do sel=$(gum table < data.csv) && break sleep 1 done [ -n "$sel" ] || exit 1
Prevention
- Avoid sending abnormal signals during the TUI
- Keep gum and Bubble Tea up to date
- Treat nil-model failures as transient and retry once
When it happens
Trigger: `tea.NewProgram(...).Run()` returns `tm == nil` — the program exits without producing a final model (abnormal teardown, tea runtime edge cases).
Common situations: Terminal teardown anomalies, signal-based abrupt exit paths of the tea runtime, or unusual terminal emulators that crash the program silently.
Related errors
- unable to run filter: %w
- unable to start program: %w
- unable to run action: %w
- failed to start tea program: %w
- failed to run write: %w
AI-assisted analysis of charmbracelet/gum@4d089f9550 (2026-08-31).
Data as JSON: /api/errors/a279a3ce0d8d491e.
Report an issue: GitHub.