charmbracelet/gum · error

no file selected

Error message

no file selected

What it means

After the file picker's bubbletea program finishes, Run checks m.selectedPath; an empty value means the program ended without a chosen path (user aborted the picker). Run surfaces this instead of printing an empty path.

Source

Thrown at file/command.go:74

		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. Treat the non-zero exit as 'user cancelled' and handle it in your script
  2. Start the picker in a directory the user can navigate and select from (check permissions)
  3. Provide an explicit fallback path when the user cancels

Example fix

// before
path=$(gum file --file) || exit 1
// after
path=$(gum file --file) || { echo "cancelled"; exit 0; }
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if ! path=$(gum file --file); then
  echo 'no file chosen (user cancelled)'
  exit 0
fi

Prevention

When it happens

Trigger: tea.Program.Run() succeeds but the model's selectedPath is empty — the user exited the filepicker without choosing a file/directory (esc/ctrl-c/q).

Common situations: Users cancelling out of the picker; scripts assuming a file is always chosen; permission-restricted directories where nothing can be selected and the user quits.

Related errors


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