clockworklabs/SpacetimeDB · error

Invalid publish response

Error message

Invalid publish response

What it means

After a successful environment PUT, the CLI parses the response body as `name::PublishResult`. If the body is absent or not valid JSON in the expected shape, the `json()` call fails and this error is thrown. Like error 43, this means a 2xx response did not carry the expected structured result.

Solutions

  1. Confirm the `--server` URL targets the SpacetimeDB API host directly, not a proxy or dashboard.
  2. Align CLI and server versions (`spacetime --version`) and upgrade whichever is stale.
  3. Curl the same PUT endpoint to inspect the raw body the server returns.
  4. Retry to rule out a truncated response; bypass proxies/CDNs if present.

Example fix

// before
spacetime publish -s https://gateway.example mydb  # 200 empty body -> Invalid publish response
// after
spacetime publish -s https://spacetimedb.example mydb
Defensive patterns

Strategy: retry

Validate before calling

// confirm server returns JSON content-type on publish endpoints
curl -sI "$SERVER/v1/database" | grep -qi 'content-type: .*json' || echo "server not returning JSON"

Try / catch

// retry with backoff on unparseable success responses
match publish_env().await {
    Err(e) if e.to_string().contains("Invalid publish response") => {
        tokio::time::sleep(Duration::from_secs(2)).await;
        publish_env().await
    }
    other => other,
}

Prevention

When it happens

Trigger: Server returns 2xx with empty body or non-JSON content; intermediary proxy rewrites the response; server version returns a PublishResult shape the CLI cannot deserialize.

Common situations: Version skew between CLI and server; publishing through a gateway that strips or transforms response bodies; misconfigured server returning empty 200s.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-20). Data as JSON: /api/errors/edcd314a1934cf2c. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/subcommands/publish/environment.rs:147

        environment: resolved.values,
        environment_remove: options.remove.clone(),
        environment_replace: options.replace,
        expected_module_version: Some(metadata.module_version),
    };
    let response = add_auth_header_opt(client.put(url), &auth)
        .header(reqwest::header::CONTENT_TYPE, CONTENT_TYPE)
        .body(request.encode()?)
        .send()
        .await?;
    anyhow::ensure!(
        response.status().is_success(),
        "Environment publish failed with HTTP {}",
        response.status()
    );
    match response
        .json::<spacetimedb_client_api_messages::name::PublishResult>()
        .await
        .map_err(|_| anyhow::anyhow!("Invalid publish response"))?
    {
        spacetimedb_client_api_messages::name::PublishResult::Success { database_identity, .. } => {
            println!("Updated environment for database {database_identity}");
            Ok(())
        }
        spacetimedb_client_api_messages::name::PublishResult::PermissionDenied { .. } => {
            anyhow::bail!("Permission denied publishing environment values")
        }
    }
}

View on GitHub (pinned to eddf9f5014)