{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/server.go#L633-L669","documentation":"When setting server info per language, Hugo constructs a `urls.BaseURL` from the resolved base URL string via `urls.NewBaseURLFromString`. This wraps a parse failure for that URL; `%q` is the offending string and `%s` the parse error.","triggerScenarios":"Fires after `fixURL` produces a string that `NewBaseURLFromString` cannot accept — typically a baseURL with control characters, an unparseable scheme, or empty after massaging. Triggered for each language config entry during `setServerInfoInConfig`.","commonSituations":"A `baseURL` in `hugo.toml` containing spaces or non-ASCII without encoding; a `--baseURL` flag with a malformed value; a multihost setup where one language's `baseURL` is invalid.","solutions":["Set a valid, absolute `baseURL` (e.g. `https://example.com/`) in `hugo.toml`.","URL-encode any special characters in the baseURL.","For multihost, verify every language's `baseURL` is individually valid.","Re-run `hugo server` after fixing; the value is re-parsed on startup."],"exampleFix":"// before\nbaseURL = \"my site.example\"\n// after\nbaseURL = \"https://my-site.example/\"","handlingStrategy":"validation","validationCode":"import \"net/url\"\nfunc validateBaseURL(s string) error {\n  if s == \"\" { return fmt.Errorf(\"empty baseURL\") }\n  u, err := url.Parse(s)\n  if err != nil { return err }\n  if u.Scheme == \"\" || u.Host == \"\" { return fmt.Errorf(\"baseURL must be absolute: %q\", s) }\n  return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always set an absolute `baseURL` (scheme + host) in `hugo.toml`.","URL-encode special characters in the baseURL.","In multihost setups, validate each language's baseURL individually."],"tags":["hugo","server","url","configuration"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}