{"record":{"id":"d3b76e7cd92ec87d","repo":"mislav/hub","slug":"error-must-enter-a-number-1-d","errorCode":null,"errorMessage":"Error: must enter a number [1-%d]","messagePattern":"Error: must enter a number \\[1-(.+?)\\]","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"github/config.go","lineNumber":257,"sourceCode":"\nfunc (c *Config) selectHost() *Host {\n\toptions := len(c.Hosts)\n\n\tif options == 1 {\n\t\treturn c.Hosts[0]\n\t}\n\n\tprompt := \"Select host:\\n\"\n\tfor idx, host := range c.Hosts {\n\t\tprompt += fmt.Sprintf(\" %d. %s\\n\", idx+1, host.Host)\n\t}\n\tprompt += fmt.Sprint(\"> \")\n\n\tui.Printf(prompt)\n\tindex := c.scanLine()\n\ti, err := strconv.Atoi(index)\n\tif err != nil || i < 1 || i > options {\n\t\tutils.Check(fmt.Errorf(\"Error: must enter a number [1-%d]\", options))\n\t}\n\n\treturn c.Hosts[i-1]\n}\n\nvar defaultConfigsFile string\n\nfunc configsFile() string {\n\tif configFromEnv := os.Getenv(\"HUB_CONFIG\"); configFromEnv != \"\" {\n\t\treturn configFromEnv\n\t}\n\tif defaultConfigsFile == \"\" {\n\t\tvar err error\n\t\tdefaultConfigsFile, err = determineConfigLocation()\n\t\tutils.Check(err)\n\t}\n\treturn defaultConfigsFile\n}","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/github/config.go#L239-L275","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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 ...`)."],"exampleFix":"// before: `echo github.com | hub browse` fails\n// after\n$ echo 1 | hub browse   # enter the index, not the host name","handlingStrategy":"validation","validationCode":"// Avoid the interactive prompt entirely by pre-selecting a single host:\nif len(cfg.Hosts) > 1 {\n    os.Setenv(\"GITHUB_HOST\", cfg.Hosts[0].Host) // hub honors GITHUB_HOST\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"must enter a number\") {\n            fmt.Fprintln(os.Stderr, \"Enter the numeric index (1-N) at the host prompt\")\n            os.Exit(1)\n        }\n        panic(r)\n    }\n}()","preventionTips":["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"],"tags":["interactive","prompt","input-validation"],"backgroundTag":"invalid-user-input","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}