clockworklabs/SpacetimeDB · error
Environment publish failed with HTTP
Error message
Environment publish failed with HTTP {} What it means
`publish_only` PUTs the encoded environment update to the server and requires a success status. Any non-2xx response — authentication failure, permission denied on the database, schema/validation rejection, server error — aborts with this message including the status code.
Solutions
- Read the HTTP status: 401/403 → `spacetime login` again and confirm you own the database identity.
- Verify supplied keys/values match the module's declared environment schema (names, formats).
- Retry if the status is 5xx and check server logs/health.
- Ensure the database identity used matches the one the module was published under.
Example fix
// before spacetime publish -s https://prod.example mydb # Environment publish failed with HTTP 403 Forbidden // after: log in with the owning identity spacetime login --server https://prod.example spacetime publish -s https://prod.example mydb
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check ownership and auth before publishing env values spacetime list --server "$SERVER" | grep -q "$DB" || echo "database not found/owned by you" spacetime login show --server "$SERVER" >/dev/null || spacetime login --server "$SERVER"
Try / catch
// rust
match publish_env().await {
Err(e) if e.to_string().contains("Environment publish failed with HTTP 40") => {
relogin().await?; publish_env().await
}
other => other,
} Prevention
- Publish environment values under the same identity that owns the database.
- Validate supplied keys/values against the module's declared schema client-side first.
- For 5xx statuses, check server health before retrying.
When it happens
Trigger: PUT of the environment update returns 401/403 (bad token or not the database owner), 4xx validation error (e.g. invalid key/value against the module's declared schema), or 5xx server failure.
Common situations: Publishing environment values for a database owned by another identity; supplying values that fail `validate_supplied_values` server-side; token expiry mid-session; transient server outage.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Cannot read environment schema: HTTP
- Publish failed with HTTP
- Environment read failed with HTTP
- Invalid publish response
- Permission denied publishing environment values
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-20).
Data as JSON: /api/errors/1af5f058f9f6c598.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/publish/environment.rs:139
);
let metadata: EnvironmentMetadata = response.json().await.context("Invalid environment metadata")?;
let schema = EnvironmentSchema::new(metadata.declarations)?;
let resolved = resolve(&schema, input, |key| std::env::var_os(key))?;
options.validate_values(&resolved.values)?;
print!("{}", resolved.display());
let request = PublishRequest {
module: None,
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)