{"record":{"id":"9c919f31925b4e61","repo":"zed-industries/zed","slug":"failed-to-set-url-scheme","errorCode":null,"errorMessage":"failed to set URL scheme","messagePattern":"failed to set URL scheme","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cloud_api_client/src/websocket/native.rs","lineNumber":73,"sourceCode":"            }\n        });\n\n        (message_rx.into_stream().boxed(), task)\n    }\n}\n\nimpl CloudApiClient {\n    pub fn connect(self: &std::sync::Arc<Self>, cx: &App) -> Result<Task<Result<Connection>>> {\n        let mut connect_url = self\n            .http_client\n            .build_zed_cloud_url(\"/client/users/connect\")?;\n        connect_url\n            .set_scheme(match connect_url.scheme() {\n                \"https\" => \"wss\",\n                \"http\" => \"ws\",\n                scheme => Err(anyhow!(\"invalid URL scheme: {scheme}\"))?,\n            })\n            .map_err(|_| anyhow!(\"failed to set URL scheme\"))?;\n\n        let credentials = self.credentials.read();\n        let credentials = credentials.as_ref().context(\"no credentials provided\")?;\n        let authorization_header = format!(\"{} {}\", credentials.user_id, credentials.access_token);\n\n        Ok(gpui_tokio::Tokio::spawn_result(cx, async move {\n            let websocket = WebSocket::connect(connect_url)\n                .with_request(\n                    request::Builder::new()\n                        .header(\"Authorization\", authorization_header)\n                        .header(PROTOCOL_VERSION_HEADER_NAME, PROTOCOL_VERSION.to_string()),\n                )\n                .await?;\n\n            Ok(Connection::new(websocket))\n        }))\n    }\n}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/cloud_api_client/src/websocket/native.rs#L55-L91","documentation":"After mapping the scheme, url::Url::set_scheme (https→wss / http→ws) itself failed. The url crate rejects scheme changes that alter the URL's shape (for example URLs without a host, or special↔non-special scheme transitions), so the connect URL could not be rewritten.","triggerScenarios":"set_scheme returns Err when the URL cannot legally switch to ws/wss — typically a base URL with no host component (relative or malformed) or an unusual scheme/host combination.","commonSituations":"A cloud base URL like `https://` with empty host, or a proxy-generated URL missing the hostname; config values assembled by string concatenation.","solutions":["Use a fully-qualified absolute base URL including host: `https://cloud.example.com`","Validate the parsed URL has a host before attempting the connection","Log the resolved connect URL once during setup to catch malformed config early"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let mut connect_url = http_client.build_zed_cloud_url(\"/client/users/connect\")?;\nif connect_url.host_str().is_none() {\n    anyhow::bail!(\"cloud URL has no host: {connect_url}\");\n}\nconnect_url.set_scheme(\"wss\").map_err(|_| anyhow!(\"failed to set URL scheme\"))?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject base URLs without a host before any connect attempt","Build URLs via a single helper that asserts host presence","Test URL rewriting in unit tests when adding custom base-URL support"],"tags":["configuration","url","websocket"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}