{"record":{"id":"c936db0b54c09b45","repo":"clockworklabs/SpacetimeDB","slug":"environment-key-is-absent","errorCode":null,"errorMessage":"Environment key is absent","messagePattern":"Environment key is absent","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/env.rs","lineNumber":162,"sourceCode":"            \"Environment read value exceeds limit\"\n        );\n    }\n    match query {\n        Query::List => {\n            let mut rows: Vec<_> = result.rows.iter().collect();\n            rows.sort_unstable_by(|a, b| a[0].cmp(&b[0]));\n            let rows = rows.into_iter().map(|row| {\n                Ok::<_, std::convert::Infallible>(spacetimedb_lib::sats::product![row[0].as_str(), row[1].as_str()])\n            });\n            let table = sql::build_table(\n                spacetimedb_lib::sats::satn::PsqlClient::SpacetimeDB,\n                &result.schema,\n                rows,\n            )?;\n            Ok(format!(\"{table}\\n\"))\n        }\n        Query::Get(_) => {\n            ensure!(result.rows.len() == 1, \"Environment key is absent\");\n            Ok(format!(\"{}\\n\", result.rows[0][0]))\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    fn body(columns: &[&'static str], rows: Vec<Vec<&str>>) -> Vec<u8> {\n        serde_json::to_vec(&[spacetimedb_client_api_messages::http::SqlStmtResult {\n            schema: spacetimedb_lib::sats::ProductType::from_iter(\n                columns\n                    .iter()\n                    .map(|column| (*column, spacetimedb_lib::AlgebraicType::String)),\n            ),\n            rows,\n            total_duration_micros: 0,\n            stats: Default::default(),","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/env.rs#L144-L180","documentation":"Thrown by `render` in the `Query::Get(_)` branch when a get-single-key environment read returns zero rows instead of exactly one. The key you asked for does not exist in the environment, so there is no value to print.","triggerScenarios":"`spacetime env get KEY` executes successfully but `result.rows.len() == 0` — the key was never set, was already unset, or the query targeted a different database/environment than the one where the key exists.","commonSituations":"Typo in the key name; key set on a different database; key removed by another developer or a deploy with `--unset-env`; case-sensitivity mismatch in the key.","solutions":["Run `spacetime env list` to see which keys actually exist.","Check the key spelling and case exactly.","Confirm you targeted the same database/identity where the key was set.","Set the key first with `spacetime env set KEY value` if it is missing."],"exampleFix":"// before\nspacetime env get API_KEY   # Environment key is absent\n// after\nspacetime env list          # shows api_key exists\nspacetime env get api_key","handlingStrategy":"validation","validationCode":"// verify the key exists before `env get`\nlet list = cmd(\"spacetime env list\")?;\nif !list.contains(key) { return Err(format!(\"{key} not set\")); }","typeGuard":null,"tryCatchPattern":"match env_get(key) {\n    Err(e) if e.to_string().contains(\"Environment key is absent\") => {\n        // fall back to a default value or set the key\n    }\n    other => other?,\n}","preventionTips":["Run `spacetime env list` to confirm key names before getting them.","Watch for case sensitivity in key names.","Check whether deploys with --unset-env removed your key.","Target the same database/identity where keys were set."],"tags":["cli","spacetimedb","environment","not-found"],"backgroundTag":"missing-env-var","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"}