clockworklabs/SpacetimeDB · error · anyhow::Error
( ) from url ( )
Error message
{status_desc} ({status}) from url ({url}) What it means
Raised by the CLI's HTTP response helper when a request to a SpacetimeDB endpoint returned an error status whose body is not the expected JSON content-type (e.g. an HTML error page), so the normal structured error decoding cannot apply. The message carries the status description, numeric code, URL, and the raw response text is attached as anyhow context.
Solutions
- Verify the server URL and port (`spacetime server list`), then probe with `curl -i <url>` to see the raw status and body the CLI is hitting
- If a proxy fronts the server, fix its routing/timeouts so SpacetimeDB's JSON errors pass through unmangled
- For 5xx during restarts, wait for the server (`spacetime server ping <name>`) and retry
- Read the response text included in the error context — it usually names the real underlying problem (404 route, bad gateway, auth page)
Defensive patterns
Strategy: try-catch
Validate before calling
# bash: confirm the endpoint speaks the expected API before running CLI commands
curl -fsS -o /dev/null -w '%{http_code} %{content_type}\n' "$URL/database" || echo "endpoint unhealthy or not SpacetimeDB" Try / catch
// Inspect status + content-type and branch: retry 5xx transient, surface 4xx body
match resp.error_for_status() {
Ok(r) if r.headers().get(CONTENT_TYPE).map_or(false, |v| v.starts_with("application/json")) => parse_json(r),
Err(e) if e.status().map_or(false, |s| s.is_server_error()) => retry_with_backoff(),
Err(e) => surf_non_json_body(e).await, // log body text for diagnosis
} Prevention
- Health-check server URLs (curl -i) when adding them: `spacetime server add` fetches a fingerprint and fails early on wrong endpoints
- Keep proxies from rewriting SpacetimeDB error responses into HTML pages
- Treat non-JSON error bodies as configuration/routing problems first, not as SDK bugs
When it happens
Trigger: Any CLI HTTP call (publish, sql, login, fingerprint fetch...) that gets 4xx/5xx with a non-JSON body: pointing --url at a non-SpacetimeDB site or wrong port, reverse-proxy 502/503 HTML pages, Cloudflare-style challenges, 404s from wrong paths.
Common situations: Wrong server URL (website instead of the database server); server behind nginx/CDN returning HTML error pages; spacetimedb restarting or crashed while the proxy stays up; captive portals intercepting requests.
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
- {e}
- HTTP response from url
- Cannot read environment schema: HTTP
- Environment read failed with HTTP
- Environment read response exceeds limit
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/7999cc2b953a5469.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/util.rs:88
impl ResponseExt for reqwest::Response {
async fn ensure_content_type(self, content_type: &str) -> anyhow::Result<Self> {
let status = self.status();
if self
.headers()
.get(http::header::CONTENT_TYPE)
.is_some_and(|ty| ty == content_type)
{
return Ok(self);
}
let url = self.url();
let Some(status_desc) = err_status_desc(status) else {
anyhow::bail!("HTTP response from url ({url}) was success but did not have content-type: {content_type}");
};
let url = url.to_string();
let status_err = match self.error_for_status_ref() {
Err(e) => anyhow::Error::from(e),
Ok(_) => anyhow::anyhow!("{status_desc} ({status}) from url ({url})"),
};
let err = match self.text().await {
Ok(text) => status_err.context(text),
Err(err) => anyhow::Error::from(err)
.context(format!("{status_desc} ({status})"))
.context("failed to get response text"),
};
Err(err)
}
async fn json_or_error<T: serde::de::DeserializeOwned>(self) -> anyhow::Result<T> {
let status = self.status();
self.ensure_content_type("application/json")
.await?
.json()
.await
.map_err(|err| {
let mut err = anyhow::Error::from(err);View on GitHub (pinned to 6dee26c6ef)