clockworklabs/SpacetimeDB · error
Environment read failed with HTTP
Error message
Environment read failed with HTTP {} What it means
Thrown by `fetch` in crates/cli/src/subcommands/env.rs when the HTTP request used to read a SpacetimeDB environment's variables (`spacetime env get`/`env list`) returns a non-success status. The message is templated with `ensure!` and the actual `response.status()`. It indicates the server rejected the environment-read SQL query before any data was returned.
Solutions
- Re-run `spacetime login` to refresh your auth token, then retry the command.
- Verify the database name / server URL passed to the command is correct.
- Check the printed HTTP status: 401/403 means credentials, 404 means wrong target, 5xx means server-side issue.
- Confirm the server is reachable and healthy (`curl` the /health endpoint).
Example fix
// before spacetime env get MY_KEY --database typo-db // error: Environment read failed with HTTP 404 // after spacetime env get MY_KEY --database my-db # existing database, valid login
Defensive patterns
Strategy: try-catch
Try / catch
match spacetime_env_list() {
Err(e) if e.to_string().contains("Environment read failed with HTTP") => {
// inspect status, re-login / fix target, then retry once
}
Err(e) => return Err(e),
Ok(out) => println!("{out}"),
} Prevention
- Run `spacetime login` before scripted env operations.
- Verify database name and server URL in scripts.
- Handle 401/403 by refreshing credentials automatically.
When it happens
Trigger: The CLI sends a SQL query over the HTTP API via `.timeout(30s).body(query.sql()?).send().await?` and `response.status().is_success()` is false — e.g. 401/403 for bad credentials, 404 for a wrong database/identity, 400 for a malformed request.
Common situations: Running `spacetime env list` or `spacetime env get KEY` against a server you are not authenticated to, with an expired token, or pointing at a database name that does not exist; server outage returning 5xx.
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 key count exceeds limit
- Environment key is absent
- Environment read response exceeds limit
- Environment read value exceeds limit
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-09-20).
Data as JSON: /api/errors/183d72a3b3ea0abc.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/env.rs:100
"spacetime env get/list <database>",
)?;
let con = sql::parse_req(config, args, &database.database, database.server.as_deref()).await?;
let mut request = ClientApi::new(con).sql();
if let Some(confirmed) = args.get_one::<bool>("confirmed") {
request = request.query(&[("confirmed", confirmed)]);
}
print!("{}", fetch(request, query).await?);
Ok(())
}
async fn fetch(request: reqwest::RequestBuilder, query: Query) -> anyhow::Result<String> {
use futures::StreamExt;
let response = request
.timeout(std::time::Duration::from_secs(30))
.body(query.sql()?)
.send()
.await?;
ensure!(
response.status().is_success(),
"Environment read failed with HTTP {}",
response.status()
);
let mut body = Vec::new();
let limit = MAX_ENV_VARS * (MAX_ENV_KEY_BYTES + MAX_ENV_VALUE_BYTES) * 6 + 64 * 1024;
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.next().await {
let chunk = chunk?;
ensure!(
body.len().saturating_add(chunk.len()) <= limit,
"Environment read response exceeds limit"
);
body.extend_from_slice(&chunk);
}
render(&body, &query)
}
View on GitHub (pinned to eddf9f5014)