{"record":{"id":"183d72a3b3ea0abc","repo":"clockworklabs/SpacetimeDB","slug":"environment-read-failed-with-http","errorCode":null,"errorMessage":"Environment read failed with HTTP {}","messagePattern":"Environment read failed with HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/env.rs","lineNumber":100,"sourceCode":"        \"spacetime env get/list <database>\",\n    )?;\n    let con = sql::parse_req(config, args, &database.database, database.server.as_deref()).await?;\n    let mut request = ClientApi::new(con).sql();\n    if let Some(confirmed) = args.get_one::<bool>(\"confirmed\") {\n        request = request.query(&[(\"confirmed\", confirmed)]);\n    }\n    print!(\"{}\", fetch(request, query).await?);\n    Ok(())\n}\n\nasync fn fetch(request: reqwest::RequestBuilder, query: Query) -> anyhow::Result<String> {\n    use futures::StreamExt;\n    let response = request\n        .timeout(std::time::Duration::from_secs(30))\n        .body(query.sql()?)\n        .send()\n        .await?;\n    ensure!(\n        response.status().is_success(),\n        \"Environment read failed with HTTP {}\",\n        response.status()\n    );\n    let mut body = Vec::new();\n    let limit = MAX_ENV_VARS * (MAX_ENV_KEY_BYTES + MAX_ENV_VALUE_BYTES) * 6 + 64 * 1024;\n    let mut stream = response.bytes_stream();\n    while let Some(chunk) = stream.next().await {\n        let chunk = chunk?;\n        ensure!(\n            body.len().saturating_add(chunk.len()) <= limit,\n            \"Environment read response exceeds limit\"\n        );\n        body.extend_from_slice(&chunk);\n    }\n    render(&body, &query)\n}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/env.rs#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nspacetime env get MY_KEY --database typo-db\n// error: Environment read failed with HTTP 404\n// after\nspacetime env get MY_KEY --database my-db   # existing database, valid login","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match spacetime_env_list() {\n    Err(e) if e.to_string().contains(\"Environment read failed with HTTP\") => {\n        // inspect status, re-login / fix target, then retry once\n    }\n    Err(e) => return Err(e),\n    Ok(out) => println!(\"{out}\"),\n}","preventionTips":["Run `spacetime login` before scripted env operations.","Verify database name and server URL in scripts.","Handle 401/403 by refreshing credentials automatically."],"tags":["cli","http","spacetimedb","environment"],"backgroundTag":"http-error-response","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}