{"id":"463dd1403ded3723","repo":"gohugoio/hugo","slug":"failed-to-create-baseurl-from-q-s","errorCode":null,"errorMessage":"failed to create baseURL from %q: %s","messagePattern":"failed to create baseURL from %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/server.go","lineNumber":651,"sourceCode":"\t\tpanic(\"no server ports set\")\n\t}\n\treturn c.withConfE(func(conf *commonConfig) error {\n\t\tfor i, language := range conf.configs.Languages {\n\t\t\tisMultihost := conf.configs.IsMultihost\n\t\t\tvar serverPort int\n\t\t\tif isMultihost {\n\t\t\t\tserverPort = c.serverPorts[i].p\n\t\t\t} else {\n\t\t\t\tserverPort = c.serverPorts[0].p\n\t\t\t}\n\t\t\tlangConfig := conf.configs.LanguageConfigMap[language.Lang]\n\t\t\tbaseURLStr, err := c.fixURL(langConfig.BaseURL, c.r.baseURL, serverPort)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tbaseURL, err := urls.NewBaseURLFromString(baseURLStr)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create baseURL from %q: %s\", baseURLStr, err)\n\t\t\t}\n\n\t\t\tbaseURLLiveReload := baseURL\n\t\t\tif c.liveReloadPort != -1 {\n\t\t\t\tbaseURLLiveReload, _ = baseURLLiveReload.WithPort(c.liveReloadPort)\n\t\t\t}\n\t\t\tlangConfig.C.SetServerInfo(baseURL, baseURLLiveReload, c.serverInterface)\n\n\t\t}\n\t\treturn nil\n\t})\n}\n\nfunc (c *serverCommand) getErrorWithContext() any {\n\tbuildErr := c.errState.buildErr()\n\tif buildErr == nil {\n\t\treturn nil\n\t}","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/server.go#L633-L669","documentation":"When starting the server, Hugo rewrites each language's baseURL for local serving (`fixURL`) and then constructs a `urls.BaseURL` from the result. If `urls.NewBaseURLFromString` cannot parse the massaged URL string, server startup aborts with this error, showing the offending string and the underlying parse error.","triggerScenarios":"A malformed `baseURL` in the site/language config or an invalid `--baseURL`/`-b` flag value — e.g. containing spaces, illegal characters, a bad scheme, or an unparsable host — that survives `fixURL`'s best-effort `//`-prefixing but fails `url.Parse`/BaseURL validation.","commonSituations":"Typos in `hugo.toml` baseURL (`htp://`, stray quotes, spaces); templated baseURLs from CI env vars that expand empty or with newlines; per-language `baseURL` overrides in multilingual configs; passing a path-only or exotic value to `-b`.","solutions":["Check `baseURL` in your config (and per-language overrides) for typos, spaces, or invalid characters; use a full URL like `https://example.org/`.","Verify any `--baseURL` flag or env-var substitution in CI actually expands to a valid URL.","In multilingual/multihost sites, validate every language's `baseURL`, since each is processed here.","Temporarily run without `-b` to isolate whether the config or the flag is at fault."],"exampleFix":"# before (hugo.toml)\nbaseURL = \"example com/blog\"\n# after\nbaseURL = \"https://example.com/blog/\"","handlingStrategy":"validation","validationCode":"if _, err := url.Parse(baseURL); err != nil || baseURL == \"\" {\n    return fmt.Errorf(\"invalid baseURL %q: %v\", baseURL, err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-parse the baseURL with net/url before passing it to hugo","Always include a scheme (http:// or https://) in baseURL","Avoid trailing garbage, spaces, or unencoded characters in config baseURL"],"tags":["hugo-server","baseurl","url-parsing","configuration"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}