{"id":"20ed961a6eae6a11","repo":"gohugoio/hugo","slug":"failed-to-split-baseurl-hostport-w","errorCode":null,"errorMessage":"failed to split baseURL hostport: %w","messagePattern":"failed to split baseURL hostport: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/server.go","lineNumber":838,"sourceCode":"\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t}\n\n\tif useLocalhost {\n\t\tif certsSet {\n\t\t\tu.Scheme = \"https\"\n\t\t} else if u.Scheme == \"https\" {\n\t\t\tu.Scheme = \"http\"\n\t\t}\n\t\tu.Host = \"localhost\"\n\t}\n\n\tif c.serverAppend {\n\t\tif strings.Contains(u.Host, \":\") {\n\t\t\tu.Host, _, err = net.SplitHostPort(u.Host)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", fmt.Errorf(\"failed to split baseURL hostport: %w\", err)\n\t\t\t}\n\t\t}\n\t\tu.Host += fmt.Sprintf(\":%d\", port)\n\t}\n\n\treturn u.String(), nil\n}\n\nfunc (c *serverCommand) partialReRender(urls ...string) (err error) {\n\tdefer func() {\n\t\tc.errState.setWasErr(false)\n\t}()\n\tvisited := types.NewEvictingQueue[string](len(urls))\n\tfor _, url := range urls {\n\t\tvisited.Add(url)\n\t}\n\n\tvar h *hugolib.HugoSites","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/server.go#L820-L856","documentation":"While rewriting the baseURL for serving with `--appendPort` enabled, Hugo strips any existing port from the URL's host before appending the live server port. If the host contains a `:` but `net.SplitHostPort` cannot split it, the baseURL host is malformed and server startup fails with this wrapped error.","triggerScenarios":"`fixURL` on a baseURL whose parsed `u.Host` contains `:` yet fails `net.SplitHostPort` — e.g. an unbracketed IPv6 address (`baseURL = \"http://::1/\"`), multiple colons, or a garbage host like `example.com:80:90`.","commonSituations":"Using IPv6 literals in `baseURL` or `-b` without square brackets (`[::1]:1313`); typos leaving a trailing/double colon in the host (`example.com::1313`); templated baseURLs in CI concatenating host and port incorrectly.","solutions":["Fix the host portion of `baseURL`: IPv6 literals must be bracketed, e.g. `http://[::1]:1313/`.","Remove stray or duplicated colons from the configured baseURL or `--baseURL` flag value.","Since Hugo appends the port itself when `--appendPort` is on (the default), you can omit the port from baseURL entirely."],"exampleFix":"# before (hugo.toml)\nbaseURL = \"http://::1/\"\n# after\nbaseURL = \"http://[::1]/\"","handlingStrategy":"validation","validationCode":"if _, _, err := net.SplitHostPort(u.Host); err != nil {\n    // no port present — acceptable, but make sure host isn't malformed (e.g. bad IPv6 brackets)\n    if strings.Contains(u.Host, \":\") {\n        return fmt.Errorf(\"malformed host:port in baseURL %q: %w\", baseURL, err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bracket IPv6 literals in baseURL: https://[::1]:1313/","Don't put multiple colons or an empty port (host:) in the baseURL","Validate baseURL with url.Parse + net.SplitHostPort in wrapper tooling before launch"],"tags":["hugo-server","baseurl","url-parsing","ipv6"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}