clockworklabs/SpacetimeDB · error · anyhow::Error

Invalid protocol: {protocol}

Error message

Invalid protocol: {protocol}

What it means

`valid_protocol_or_error` rejects any protocol string not in `VALID_PROTOCOLS`, which is exactly `["http", "https"]` (crates/cli/src/util.rs:211). It is called from `spacetime server add` and `server edit` after the scheme is split off the URL. Note the sibling helper `host_or_url_to_host_and_protocol` only yields `Some(protocol)` for valid schemes, so in practice this guard is defensive; some malformed-scheme inputs can even panic earlier in that helper's `unwrap()`.

Source

Thrown at crates/cli/src/subcommands/server.rs:184

    let mut table = Table::new(&rows);
    table
        .with(Style::empty())
        .with(Modify::new(Columns::first()).with(Alignment::right()));
    println!("{table}");

    Ok(())
}

pub async fn exec_set_default(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
    let server = args.get_one::<String>("server").unwrap();
    config.set_default_server(server)?;
    config.save();
    Ok(())
}

fn valid_protocol_or_error(protocol: &str) -> anyhow::Result<()> {
    if !VALID_PROTOCOLS.contains(&protocol) {
        Err(anyhow::anyhow!("Invalid protocol: {protocol}"))
    } else {
        Ok(())
    }
}

pub async fn exec_add(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
    // Trim trailing `/`s because otherwise we end up with a double `//` in some later codepaths.
    // See https://github.com/clockworklabs/SpacetimeDB/issues/1551.
    let url = args.get_one::<String>("url").unwrap().trim_end_matches('/');
    let nickname = args.get_one::<String>("name");
    let default = *args.get_one::<bool>("default").unwrap();
    let no_fingerprint = *args.get_one::<bool>("no-fingerprint").unwrap();

    let (host, protocol) = host_or_url_to_host_and_protocol(url);
    let protocol = protocol.ok_or_else(|| anyhow::anyhow!("Invalid url: {url}"))?;

    valid_protocol_or_error(protocol)?;

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Use an `http://` or `https://` URL for the server
  2. Omit the scheme entirely and pass a bare host so the default protocol applies
  3. Double-check the pasted URL for typos in the scheme portion

Example fix

# before
spacetime server add --url ws://testnet.spacetimedb.com --name testnet
# after
spacetime server add --url https://testnet.spacetimedb.com --name testnet
Defensive patterns

Strategy: validation

Validate before calling

# Accept only http/https URLs in wrappers around `server add`
case "$1" in http://*|https://*) ;; *) echo "url must start with http:// or https://"; exit 2;; esac

Prevention

When it happens

Trigger: Passing a URL whose scheme is neither http nor https — e.g. `spacetime server add --url ws://host` or `ftp://host` — to server add/edit code paths that reach this check.

Common situations: Copying a websocket URL from client connection strings and using it as a server URL; typos like `htps://`; assuming any scheme is accepted because the flag is named `--url`.

Related errors


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