clockworklabs/SpacetimeDB · error
Publish failed with HTTP
Error message
Publish failed with HTTP {} What it means
`execute_publish_configs` POSTs the compiled module and environment payload to the server, then requires the HTTP response to be a success status via `ensure!`. Any non-2xx response (authentication failure, invalid module, name conflicts, server errors, proxy errors) aborts the publish with this message including the status code.
Solutions
- Read the printed HTTP status: 401/403 → re-authenticate (`spacetime login`), 4xx → fix the request (module errors, name conflicts), 5xx → server-side problem.
- Re-run `spacetime login` to refresh credentials, then retry the publish.
- Check the server is running the expected version and inspect its logs for the rejection reason.
- Verify network path/proxy isn't intercepting the request (status like 502/504 suggests infrastructure).
Example fix
// before spacetime publish --server https://prod.example mydb // error: Publish failed with HTTP 401 Unauthorized // after spacetime login --server https://prod.example spacetime publish --server https://prod.example mydb
Defensive patterns
Strategy: try-catch
Validate before calling
// shell pre-flight spacetime login show --server "$SERVER" >/dev/null || spacetime login --server "$SERVER"
Try / catch
// rust
match publish().await {
Err(e) if e.to_string().contains("Publish failed with HTTP") => {
if e.to_string().contains("401") || e.to_string().contains("403") {
relogin().await?; retry_publish().await
} else { Err(e) }
}
other => other,
} Prevention
- Refresh credentials (`spacetime login`) before long-running CI publishes.
- Publish to a local/test server first to catch module-level rejections.
- Check ownership of the database name before publishing to shared servers.
When it happens
Trigger: Publishing a module that fails server-side validation (HTTP 422/500), publishing with expired/invalid credentials (401/403), publishing to a database name you don't own (PermissionDenied), or hitting a proxy/CDN error page.
Common situations: Expired login token after a period of inactivity; a database already published by another identity; server version older than the CLI and rejects the payload; reverse proxy returning 502/503.
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
- Environment publish failed with HTTP
- Aborted.
- Cannot use module-specific arguments
- {e}
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-20).
Data as JSON: /api/errors/d53325b21c924fb7.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/publish.rs:775
if let Some(org) = org {
builder = builder.query(&[("org", org)]);
}
println!("Publishing module...");
builder = add_auth_header_opt(builder, &auth_header);
// Set the host type.
builder = builder.query(&[("host_type", host_type)]);
let (content_type, payload) =
publication_body(&module_schema, program_bytes, environment.values, environment_options)?;
let res = builder
.header(reqwest::header::CONTENT_TYPE, content_type)
.body(payload)
.send()
.await?;
anyhow::ensure!(res.status().is_success(), "Publish failed with HTTP {}", res.status());
let response: PublishResult = res
.json()
.await
.map_err(|_| anyhow::anyhow!("Invalid publish response"))?;
match response {
PublishResult::Success {
domain,
database_identity,
op,
} => {
let op = match op {
PublishOp::Created => "Created new",
PublishOp::Updated => "Updated",
};
if let Some(ref domain) = domain {
println!("{op} database with name: {domain}, identity: {database_identity}");
} else {
println!("{op} database with identity: {database_identity}");View on GitHub (pinned to eddf9f5014)