mislav/hub · error
invalid hostname: %q
Error message
invalid hostname: %q
What it means
PromptForHost validates any non-GitHub.com host by parsing "https://" + host with net/url before looking it up in the config. If the URL parse fails, the hostname is malformed and this error is returned. Note it only catches structurally invalid hostnames (e.g. containing spaces or control characters), not DNS or reachability problems.
Source
Thrown at github/config.go:48
User string `toml:"user"`
AccessToken string `toml:"access_token"`
Protocol string `toml:"protocol"`
UnixSocket string `toml:"unix_socket,omitempty"`
}
type Config struct {
Hosts []*Host `toml:"hosts"`
stdinScanner *bufio.Scanner
}
func (c *Config) PromptForHost(host string) (h *Host, err error) {
token := c.DetectToken()
tokenFromEnv := token != ""
if host != GitHubHost {
if _, e := url.Parse("https://" + host); e != nil {
err = fmt.Errorf("invalid hostname: %q", host)
return
}
}
h = c.Find(host)
if h != nil {
if h.User == "" {
utils.Check(CheckWriteable(configsFile()))
// User is missing from the config: this is a broken config probably
// because it was created with an old (broken) version of hub. Let's fix
// it now. See issue #1007 for details.
user := c.PromptForUser(host)
if user == "" {
utils.Check(fmt.Errorf("missing user"))
}
h.User = user
err := newConfigService().Save(configsFile(), c)
utils.Check(err)View on GitHub (pinned to 5c547ed804)
Solutions
- Fix the host string to a bare, valid hostname such as ghe.example.com (no scheme, no spaces, no path).
- Unset or correct the GITHUB_HOST environment variable if it holds an invalid value.
- Sanitize input before calling DefaultHost/DefaultHostNoPrompt (strip scheme, trim spaces).
Example fix
// before
host := os.Getenv("GITHUB_HOST") // "https://ghe.corp.example"
// after
host := strings.TrimPrefix(strings.TrimPrefix(os.Getenv("GITHUB_HOST"), "https://"), "http://")
c.PromptForHost(host) Defensive patterns
Strategy: validation
Validate before calling
host := os.Getenv("GITHUB_HOST")
host = strings.TrimPrefix(strings.TrimPrefix(host, "https://"), "http://")
host = strings.TrimSpace(host)
if _, err := url.Parse("https://" + host); err != nil {
log.Fatalf("GITHUB_HOST is not a valid hostname: %q", host)
} Type guard
func validHost(host string) bool {
if host == "github.com" {
return true
}
_, err := url.Parse("https://" + host)
return err == nil && host != ""
} Try / catch
h, err := cfg.PromptForHost(host)
if err != nil && strings.HasPrefix(err.Error(), "invalid hostname") {
return fmt.Errorf("bad host %q: %w", host, err)
} Prevention
- Store bare hostnames (no scheme, no path) in GITHUB_HOST and hub config
- Trim whitespace and scheme prefixes from user-supplied host strings
- Validate hostnames with url.Parse before passing to DefaultHost
When it happens
Trigger: Calling PromptForHost (indirectly via DefaultHost or DefaultHostNoPrompt) with a host string that is not exactly github.com and cannot be parsed as a URL host, e.g. "my host.example.com" or a host with illegal characters.
Common situations: Typo or paste error in GITHUB_HOST or in the host name during first-run interactive setup; leading/trailing whitespace or protocol prefix ("https://ghe.example.com") accidentally included in the host value.
Related errors
- value of host entry is must be array but got %#v
- Please set $BROWSER to a web launcher
- Error: couldn't detect shell type. Please specify your shell
- hub alias: unsupported shell supported shells: %s
- Aborting creation due to empty issue title
AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01).
Data as JSON: /api/errors/8448d1b8747c8a73.
Report an issue: GitHub.