clockworklabs/SpacetimeDB · error · anyhow::Error

Invalid protocol: {protocol}

Error message

Invalid protocol: {protocol}

What it means

url_to_host_and_protocol in the CLI only accepts http and https (VALID_PROTOCOLS at crates/cli/src/util.rs:211). When a URL contains '://' but the scheme is anything else, this error is returned naming the rejected scheme. Other schemes such as ws/wss are intentionally rejected at this call site even though clients use them for subscriptions.

Source

Thrown at crates/cli/src/util.rs:294

            .any(|entry| entry.path().extension() == Some("csproj".as_ref()))
    {
        Ok(ModuleLanguage::Csharp)
    } else if path_to_module.join("package.json").exists() {
        Ok(ModuleLanguage::Javascript)
    } else if path_to_module.join("CMakeLists.txt").exists() {
        Ok(ModuleLanguage::Cpp)
    } else {
        anyhow::bail!("Could not detect the language of the module. Are you in a SpacetimeDB project directory?")
    }
}

pub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> {
    if contains_protocol(url) {
        let protocol = url.split("://").next().unwrap();
        let host = url.split("://").last().unwrap();

        if !VALID_PROTOCOLS.contains(&protocol) {
            Err(anyhow::anyhow!("Invalid protocol: {protocol}"))
        } else {
            Ok((host, protocol))
        }
    } else {
        Err(anyhow::anyhow!("Invalid url: {url}"))
    }
}

pub fn contains_protocol(name_or_url: &str) -> bool {
    name_or_url.contains("://")
}

pub fn host_or_url_to_host_and_protocol(host_or_url: &str) -> (&str, Option<&str>) {
    if contains_protocol(host_or_url) {
        let (host, protocol) = url_to_host_and_protocol(host_or_url).unwrap();
        (host, Some(protocol))
    } else {
        (host_or_url, None)

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Replace the scheme with http:// or https:// (e.g. wss://host becomes https://host).
  2. For local development set `spacetime server set http://127.0.0.1:3000` or use the default.
  3. Inspect stored servers with `spacetime server list` and reset any entry with a bad scheme.
  4. Double-check the exact spelling `scheme://host[:port]` with two slashes.

Example fix

# before
spacetime server set wss://testnet.spacetimedb.com
# after
spacetime server set https://testnet.spacetimedb.com
Defensive patterns

Strategy: validation

Validate before calling

function assertSpacetimeUrl(url: string): void {
  const scheme = url.split("://")[0];
  if (!url.includes("://") || !['http', 'https'].includes(scheme)) {
    throw new Error(`URL must start with http:// or https:// — got '${scheme}' in '${url}'`);
  }
}

Type guard

function isSpacetimeUrl(url: string): boolean {
  return /^https?:\/\/.+/.test(url);
}

Prevention

When it happens

Trigger: Passing --url or `spacetime server set` a ws:// or wss:// connection string copied from client SDK docs; a scheme typo like `http//` or `https:/host`; a spacetime.json server url with an unsupported scheme such as ftp:// or unix://.

Common situations: Copying a wss:// subscription URL from TypeScript/React quickstarts into a CLI server flag; switching between SDK connection strings and CLI server URLs; typos when hand-editing config files.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/c8b620ca22767804. Report an issue: GitHub.