clockworklabs/SpacetimeDB · error · anyhow::Error

Invalid url

Error message

Invalid url: {url}

What it means

url_to_host_and_protocol requires a scheme-qualified URL: the input contains no '://' at all, so no protocol can be split out and the whole value is reported as invalid. Unlike host_or_url_to_host_and_protocol (which tolerates bare hostnames), this helper has no bare-host fallback.

Solutions

  1. Provide the full URL including scheme: `http://host` or `https://host:port`
  2. Trim whitespace and re-check the stored value in the config/CLI history
  3. If a bare hostname must be supported, prefix a default scheme before passing it in

Example fix

# before
spacetime server add --url mainnet.spacetimedb.com

# after
spacetime server add --url https://mainnet.spacetimedb.com
Defensive patterns

Strategy: validation

Validate before calling

fn has_scheme(url: &str) -> bool {
    url.contains("://")
}

Prevention

When it happens

Trigger: Calling code paths that use url_to_host_and_protocol with a bare hostname, host:port, or malformed string lacking '://'.

Common situations: Config values that store just a hostname; user input not normalized to a full URL; strings with whitespace or a stripped scheme after templating.

Related errors


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

Appendix: 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 6dee26c6ef)