charmbracelet/gum · error

unable to pick selection: %w

Error message

unable to pick selection: %w

What it means

This wraps any error from the bubbletea program that runs the file picker. It indicates the interactive TUI failed to start or crashed, not that the user declined to pick a file.

Source

Thrown at file/command.go:70

		filepicker:  fp,
		padding:     []int{top, right, bottom, left},
		showHelp:    o.ShowHelp,
		help:        help.New(),
		keymap:      defaultKeymap(),
		headerStyle: o.HeaderStyle.ToLipgloss(),
		header:      o.Header,
	}

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

	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.selectedPath == "" {
		return errors.New("no file selected")
	}

	fmt.Println(m.selectedPath)
	return nil
}

View on GitHub (pinned to 4d089f9550)

Solutions

  1. Inspect the wrapped cause for context cancellation vs TTY problems
  2. Run inside a real terminal or allocate one (e.g. `script -qec`) in CI
  3. Extend the timeout or fall back to a non-interactive file listing

Example fix

// before
gum file --timeout 1s  # unable to pick selection: context deadline exceeded
// after
gum file --timeout 30s
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if ! path=$(gum file --file 2>err.log); then
  cat err.log >&2  # inspect wrapped cause: TTY vs context deadline
fi

Prevention

When it happens

Trigger: tea.NewProgram(m, tea.WithOutput(os.Stderr), tea.WithContext(ctx)).Run() returns non-nil err — context cancelled/timed out, no usable TTY on stderr, or bubbletea internal error.

Common situations: Timeout via timeout.Context expiring; CI environments without a TTY; stderr piped into a closed reader.

Related errors


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