{"record":{"id":"8448d1b8747c8a73","repo":"mislav/hub","slug":"invalid-hostname-q","errorCode":null,"errorMessage":"invalid hostname: %q","messagePattern":"invalid hostname: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"github/config.go","lineNumber":48,"sourceCode":"\tUser        string `toml:\"user\"`\n\tAccessToken string `toml:\"access_token\"`\n\tProtocol    string `toml:\"protocol\"`\n\tUnixSocket  string `toml:\"unix_socket,omitempty\"`\n}\n\ntype Config struct {\n\tHosts []*Host `toml:\"hosts\"`\n\n\tstdinScanner *bufio.Scanner\n}\n\nfunc (c *Config) PromptForHost(host string) (h *Host, err error) {\n\ttoken := c.DetectToken()\n\ttokenFromEnv := token != \"\"\n\n\tif host != GitHubHost {\n\t\tif _, e := url.Parse(\"https://\" + host); e != nil {\n\t\t\terr = fmt.Errorf(\"invalid hostname: %q\", host)\n\t\t\treturn\n\t\t}\n\t}\n\n\th = c.Find(host)\n\tif h != nil {\n\t\tif h.User == \"\" {\n\t\t\tutils.Check(CheckWriteable(configsFile()))\n\t\t\t// User is missing from the config: this is a broken config probably\n\t\t\t// because it was created with an old (broken) version of hub. Let's fix\n\t\t\t// it now. See issue #1007 for details.\n\t\t\tuser := c.PromptForUser(host)\n\t\t\tif user == \"\" {\n\t\t\t\tutils.Check(fmt.Errorf(\"missing user\"))\n\t\t\t}\n\t\t\th.User = user\n\t\t\terr := newConfigService().Save(configsFile(), c)\n\t\t\tutils.Check(err)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/github/config.go#L30-L66","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nhost := os.Getenv(\"GITHUB_HOST\") // \"https://ghe.corp.example\"\n// after\nhost := strings.TrimPrefix(strings.TrimPrefix(os.Getenv(\"GITHUB_HOST\"), \"https://\"), \"http://\")\nc.PromptForHost(host)","handlingStrategy":"validation","validationCode":"host := os.Getenv(\"GITHUB_HOST\")\nhost = strings.TrimPrefix(strings.TrimPrefix(host, \"https://\"), \"http://\")\nhost = strings.TrimSpace(host)\nif _, err := url.Parse(\"https://\" + host); err != nil {\n    log.Fatalf(\"GITHUB_HOST is not a valid hostname: %q\", host)\n}","typeGuard":"func validHost(host string) bool {\n    if host == \"github.com\" {\n        return true\n    }\n    _, err := url.Parse(\"https://\" + host)\n    return err == nil && host != \"\"\n}","tryCatchPattern":"h, err := cfg.PromptForHost(host)\nif err != nil && strings.HasPrefix(err.Error(), \"invalid hostname\") {\n    return fmt.Errorf(\"bad host %q: %w\", host, err)\n}","preventionTips":["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"],"tags":["configuration","validation","hostname"],"backgroundTag":"invalid-hostname","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}