clockworklabs/SpacetimeDB · error · anyhow::Error

Invalid url: {url}

Error message

Invalid url: {url}

What it means

Returned by url_to_host_and_protocol when the input contains no '://' separator at all, so it cannot be split into scheme and host. At this call site the CLI requires a fully-qualified URL with an explicit scheme; a bare host or host:port is rejected.

Source

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

    } 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)
    }
}

/// Prompt the user for `y` or `n` from stdin.
///

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Prefix the scheme: use `http://127.0.0.1:3000` locally and `https://...` for remote servers.
  2. Re-set the server URL in full form: `spacetime server set https://testnet.spacetimedb.com`.
  3. Check the flag's expectations — URL flags (--url, server config) require scheme://host, not bare hosts.
  4. Search config and env for hostname values missing '://' and fix them.

Example fix

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

Strategy: validation

Validate before calling

function normalizeServerUrl(hostOrUrl: string): string {
  return hostOrUrl.includes("://") ? hostOrUrl : `https://${hostOrUrl}`;
}
// use: spacetime server set $(normalizeServerUrl(process.env.STDB_HOST!))

Type guard

function hasScheme(url: string): boolean {
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(url);
}

Prevention

When it happens

Trigger: Passing `127.0.0.1:3000` or `localhost` where a URL is required; a scheme typo that drops the slashes (`http:` without `//`); env vars or config values holding a bare hostname being fed to --url.

Common situations: Assuming the CLI defaults to http like some SDKs do; copy-paste truncation losing the scheme; hand-written SPACETIMEDB_HOST-style variables without a protocol.

Related errors


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