mislav/hub · warning
Error: must enter a number [1-%d]
Error message
Error: must enter a number [1-%d]
What it means
In selectHost, the user is shown a numbered list of configured hosts and asked to pick one. If the entered text is not an integer or is outside the range [1, options], utils.Check raises this error and the program exits. It is an input-validation guard on the interactive host selection prompt.
Source
Thrown at github/config.go:257
func (c *Config) selectHost() *Host {
options := len(c.Hosts)
if options == 1 {
return c.Hosts[0]
}
prompt := "Select host:\n"
for idx, host := range c.Hosts {
prompt += fmt.Sprintf(" %d. %s\n", idx+1, host.Host)
}
prompt += fmt.Sprint("> ")
ui.Printf(prompt)
index := c.scanLine()
i, err := strconv.Atoi(index)
if err != nil || i < 1 || i > options {
utils.Check(fmt.Errorf("Error: must enter a number [1-%d]", options))
}
return c.Hosts[i-1]
}
var defaultConfigsFile string
func configsFile() string {
if configFromEnv := os.Getenv("HUB_CONFIG"); configFromEnv != "" {
return configFromEnv
}
if defaultConfigsFile == "" {
var err error
defaultConfigsFile, err = determineConfigLocation()
utils.Check(err)
}
return defaultConfigsFile
}View on GitHub (pinned to 5c547ed804)
Solutions
- Re-run the command and enter only the numeric list index shown next to the desired host (1-N).
- Trim ~/.config/hub to a single host entry so the prompt never appears.
- Pipe a valid number into the prompt when automating (e.g. `echo 1 | hub ...`).
Example fix
// before: `echo github.com | hub browse` fails // after $ echo 1 | hub browse # enter the index, not the host name
Defensive patterns
Strategy: validation
Validate before calling
// Avoid the interactive prompt entirely by pre-selecting a single host:
if len(cfg.Hosts) > 1 {
os.Setenv("GITHUB_HOST", cfg.Hosts[0].Host) // hub honors GITHUB_HOST
} Try / catch
defer func() {
if r := recover(); r != nil {
if strings.Contains(fmt.Sprint(r), "must enter a number") {
fmt.Fprintln(os.Stderr, "Enter the numeric index (1-N) at the host prompt")
os.Exit(1)
}
panic(r)
}
}() Prevention
- Keep only one host entry in ~/.config/hub to skip the selection prompt
- When scripting, pipe a valid integer (e.g. `echo 1 |`) into the prompt
- Set GITHUB_HOST so DefaultHost resolves without asking
When it happens
Trigger: Typing a non-numeric string (e.g. "github.com") or a number < 1 or > number-of-options at the "Select which host" prompt during DefaultHost when multiple hosts are configured.
Common situations: First-run setup with several host entries in ~/.config/hub; pasting a hostname instead of the list number; scripts feeding invalid input into the prompt.
Related errors
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/d3b76e7cd92ec87d.
Report an issue: GitHub.