zed-industries/zed · error

failed to set URL scheme

Error message

failed to set URL scheme

What it means

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.

Source

Thrown at crates/cloud_api_client/src/websocket/native.rs:73

            }
        });

        (message_rx.into_stream().boxed(), task)
    }
}

impl CloudApiClient {
    pub fn connect(self: &std::sync::Arc<Self>, cx: &App) -> Result<Task<Result<Connection>>> {
        let mut connect_url = self
            .http_client
            .build_zed_cloud_url("/client/users/connect")?;
        connect_url
            .set_scheme(match connect_url.scheme() {
                "https" => "wss",
                "http" => "ws",
                scheme => Err(anyhow!("invalid URL scheme: {scheme}"))?,
            })
            .map_err(|_| anyhow!("failed to set URL scheme"))?;

        let credentials = self.credentials.read();
        let credentials = credentials.as_ref().context("no credentials provided")?;
        let authorization_header = format!("{} {}", credentials.user_id, credentials.access_token);

        Ok(gpui_tokio::Tokio::spawn_result(cx, async move {
            let websocket = WebSocket::connect(connect_url)
                .with_request(
                    request::Builder::new()
                        .header("Authorization", authorization_header)
                        .header(PROTOCOL_VERSION_HEADER_NAME, PROTOCOL_VERSION.to_string()),
                )
                .await?;

            Ok(Connection::new(websocket))
        }))
    }
}

View on GitHub (pinned to bc538def45)

Solutions

  1. Use a fully-qualified absolute base URL including host: `https://cloud.example.com`
  2. Validate the parsed URL has a host before attempting the connection
  3. Log the resolved connect URL once during setup to catch malformed config early
Defensive patterns

Strategy: validation

Validate before calling

let mut connect_url = http_client.build_zed_cloud_url("/client/users/connect")?;
if connect_url.host_str().is_none() {
    anyhow::bail!("cloud URL has no host: {connect_url}");
}
connect_url.set_scheme("wss").map_err(|_| anyhow!("failed to set URL scheme"))?;

Prevention

When it happens

Trigger: 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.

Common situations: A cloud base URL like `https://` with empty host, or a proxy-generated URL missing the hostname; config values assembled by string concatenation.

Related errors


AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16). Data as JSON: /api/errors/9c919f31925b4e61. Report an issue: GitHub.