{"record":{"id":"35e5f9b54a6493ab","repo":"gohugoio/hugo","slug":"cannot-determine-baseurl-for-protocol-q","errorCode":null,"errorMessage":"cannot determine BaseURL for protocol %q","messagePattern":"cannot determine BaseURL for protocol %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/urls/baseURL.go","lineNumber":72,"sourceCode":"func (b BaseURL) WithProtocol(protocol string) (BaseURL, error) {\n\tu := b.URL()\n\n\tscheme := protocol\n\tisFullProtocol := strings.HasSuffix(scheme, \"://\")\n\tisOpaqueProtocol := strings.HasSuffix(scheme, \":\")\n\n\tif isFullProtocol {\n\t\tscheme = strings.TrimSuffix(scheme, \"://\")\n\t} else if isOpaqueProtocol {\n\t\tscheme = strings.TrimSuffix(scheme, \":\")\n\t}\n\n\tu.Scheme = scheme\n\n\tif isFullProtocol && u.Opaque != \"\" {\n\t\tu.Opaque = \"//\" + u.Opaque\n\t} else if isOpaqueProtocol && u.Opaque == \"\" {\n\t\treturn BaseURL{}, fmt.Errorf(\"cannot determine BaseURL for protocol %q\", protocol)\n\t}\n\n\treturn newBaseURLFromURL(u)\n}\n\nfunc (b BaseURL) WithPort(port int) (BaseURL, error) {\n\tu := b.URL()\n\tu.Host = u.Hostname() + \":\" + strconv.Itoa(port)\n\treturn newBaseURLFromURL(u)\n}\n\n// URL returns a copy of the internal URL.\n// The copy can be safely used and modified.\nfunc (b BaseURL) URL() *url.URL {\n\tc := *b.url\n\treturn &c\n}\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/common/urls/baseURL.go#L54-L90","documentation":"Returned by BaseURL.WithProtocol when the supplied protocol is opaque (ends with a single ':', e.g. 'mailto:') but the BaseURL's underlying URL has no opaque component to attach it to. WithProtocol only supports opaque protocols when the existing URL is itself opaque; otherwise it cannot construct a valid BaseURL.","triggerScenarios":"Calling baseURL.WithProtocol(\"mailto:\") (or any ':' suffix without '//') on a BaseURL whose URL.Opaque is empty because the original baseURL was a normal scheme://path form.","commonSituations":"Output-format or media-type configuration that tries to relabel a regular http(s) BaseURL with an opaque protocol like 'mailto:', 'tel:', or 'javascript:'.","solutions":["Use a full 'scheme://' protocol form unless the BaseURL is genuinely opaque.","Construct the opaque BaseURL from scratch via NewBaseURLFromString('mailto:user@example.com').","Avoid WithProtocol for opaque schemes on path-based BaseURLs."],"exampleFix":"// before\nb,_ := urls.NewBaseURLFromString(\"https://site.com/\")\nb.WithProtocol(\"mailto:\")\n// after\nb,_ := urls.NewBaseURLFromString(\"mailto:user@example.com\")","handlingStrategy":"validation","validationCode":"func canWithProtocol(b urls.BaseURL, protocol string) bool {\n  opaque := strings.HasSuffix(protocol, \":\") && !strings.HasSuffix(protocol, \"://\")\n  return !opaque || b.URL().Opaque != \"\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'scheme://' protocols with normal BaseURLs.","Build opaque BaseURLs from scratch via NewBaseURLFromString for mailto:/tel:.","Avoid relabeling path-based BaseURLs with opaque schemes."],"tags":["urls","baseurl","protocol","opaque","config"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}