{"record":{"id":"09e3ccfebe1d65dc","repo":"zed-industries/zed","slug":"failed-to-get-host-from-bitbucket-base-url","errorCode":null,"errorMessage":"failed to get host from bitbucket base url","messagePattern":"failed to get host from bitbucket base url","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/git_hosting_providers/src/providers/bitbucket.rs","lineNumber":116,"sourceCode":"            Url::parse(&format!(\"https://{}\", host))?,\n        ))\n    }\n\n    fn is_self_hosted(&self) -> bool {\n        self.base_url\n            .host_str()\n            .is_some_and(|host| host != \"bitbucket.org\")\n    }\n\n    async fn fetch_bitbucket_commit_author(\n        &self,\n        repo_owner: &str,\n        repo: &str,\n        commit: &str,\n        client: &Arc<dyn HttpClient>,\n    ) -> Result<Option<String>> {\n        let Some(host) = self.base_url.host_str() else {\n            bail!(\"failed to get host from bitbucket base url\");\n        };\n        let is_self_hosted = self.is_self_hosted();\n        let url = if is_self_hosted {\n            format!(\n                \"https://{host}/rest/api/latest/projects/{repo_owner}/repos/{repo}/commits/{commit}?avatarSize=128\"\n            )\n        } else {\n            format!(\"https://api.{host}/2.0/repositories/{repo_owner}/{repo}/commit/{commit}\")\n        };\n\n        let request = Request::get(&url)\n            .header(\"Content-Type\", \"application/json\")\n            .follow_redirects(http_client::RedirectPolicy::FollowAll);\n\n        let mut response = client\n            .send(request.body(AsyncBody::default())?)\n            .await\n            .with_context(|| format!(\"error fetching BitBucket commit details at {:?}\", url))?;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/git_hosting_providers/src/providers/bitbucket.rs#L98-L134","documentation":"fetch_bitbucket_commit_author builds an API URL from the provider's configured base URL; if url::Url::host_str() returns None, the URL has no host component (non-HTTP scheme, relative URL, or malformed parse) and the provider cannot construct a request, so it bails immediately.","triggerScenarios":"Constructing a Bitbucket provider with a base Url whose host is None — for example a Url parsed from unexpected input (a `file:` or relative URL) or a default-constructed Url — and then triggering commit-author lookup.","commonSituations":"Providers created from user-configured instance URLs or remote URLs that parsed into something hostless; partially initialized config; URL normalization stripping the host (leading slash, missing scheme before a colon-containing path).","solutions":["Validate the base URL when constructing the provider: require scheme http/https and a non-empty host.","Use Bitbucket::public_instance() for bitbucket.org and Bitbucket::from_remote_url() for self-hosted instances — both build well-formed URLs.","Log the offending base_url at construction time so misconfiguration is caught early.","Reject hostless URLs with a clear configuration error instead of failing later at fetch time."],"exampleFix":"// before\nOk(Self::new(name, base_url))\n// after\nanyhow::ensure!(\n    matches!(base_url.scheme(), \"http\" | \"https\") && base_url.host_str().is_some(),\n    \"BitBucket base URL must be an absolute HTTP(S) URL with a host: {base_url}\"\n);\nOk(Self::new(name, base_url))","handlingStrategy":"validation","validationCode":"fn valid_http_url(url: &Url) -> bool {\n    matches!(url.scheme(), \"http\" | \"https\") && url.host_str().is_some()\n}\n\nanyhow::ensure!(valid_http_url(&base_url), \"base URL must be absolute HTTP(S) with a host\");","typeGuard":"fn has_host(url: &Url) -> bool {\n    url.host_str().map(|h| !h.is_empty()).unwrap_or(false)\n}","tryCatchPattern":"if let Err(e) = provider.commit_author(..).await {\n    if e.to_string().contains(\"failed to get host\") {\n        // configuration bug: rebuild the provider from a validated URL\n    }\n    return Err(e);\n}","preventionTips":["Validate provider base URLs (scheme http/https + host) once at construction, not per request.","Construct providers via from_remote_url()/public_instance() instead of hand-building URLs.","Fail fast on malformed instance URLs in configuration with the offending value in the message."],"tags":["bitbucket","url","config","validation"],"backgroundTag":"invalid-url-host","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}