charmbracelet/gum · error

unable to pick selection: %w

Error message

unable to pick selection: %w

What it means

This wraps any error returned by the bubbletea program that renders the choose picker. It indicates the interactive UI itself failed to run or crashed, distinct from the user declining to select.

Source

Thrown at choose/command.go:154

		itemStyle:         o.ItemStyle.ToLipgloss(),
		selectedItemStyle: o.SelectedItemStyle.ToLipgloss(),
		numSelected:       currentSelected,
		showHelp:          o.ShowHelp,
		help:              help.New(),
		keymap:            km,
	}

	ctx, cancel := timeout.Context(o.Timeout)
	defer cancel()

	// Disable Keybindings since we will control it ourselves.
	tm, err := tea.NewProgram(
		m,
		tea.WithOutput(os.Stderr),
		tea.WithContext(ctx),
	).Run()
	if err != nil {
		return fmt.Errorf("unable to pick selection: %w", err)
	}
	m = tm.(model)
	if !m.submitted {
		return errors.New("nothing selected")
	}
	if o.Ordered && o.Limit > 1 {
		sort.Slice(m.items, func(i, j int) bool {
			return m.items[i].order < m.items[j].order
		})
	}

	var out []string
	for _, item := range m.items {
		if item.selected {
			out = append(out, options[item.text])
		}
	}
	tty.Println(strings.Join(out, o.OutputDelimiter))

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Check the wrapped cause (%w) — often context cancellation or TTY issues
  2. Run gum in a real terminal / allocate a TTY (e.g. `script -qec` in CI)
  3. Retry or fall back to non-interactive mode if the environment cannot host a TUI

Example fix

// before
CI: gum choose a b  # unable to pick selection: not a terminal
// after
script -qec 'gum choose a b' /dev/null
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if ! choice=$(gum choose a b c 2>err.log); then
  grep -q 'unable to pick selection' <<<"$(cat err.log)" && echo 'TUI failed; check TTY/context'
fi

Prevention

When it happens

Trigger: tea.NewProgram(m, tea.WithOutput(os.Stderr), tea.WithContext(ctx)).Run() returns a non-nil err — e.g. context cancelled, output device not a terminal/inaccessible, or bubbletea internal failure.

Common situations: Context deadline exceeded from timeout.Context; running in a non-TTY environment (CI, no controlling terminal); stderr redirected to a closed pipe.

Related errors


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