{"record":{"id":"bb535115dba546ad","repo":"clockworklabs/SpacetimeDB","slug":"environment-values-can-only-be-changed-by-publishing","errorCode":null,"errorMessage":"Environment values can only be changed by publishing","messagePattern":"Environment values can only be changed by publishing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/env.rs","lineNumber":75,"sourceCode":"            Self::Get(key) => {\n                // POSIX names cannot contain quotes or SQL syntax.\n                validate_key(key).map_err(|_| anyhow::anyhow!(\"Invalid environment key name\"))?;\n                Ok(format!(\"SELECT value FROM st_env WHERE key = '{key}'\"))\n            }\n        }\n    }\n}\n\npub async fn exec(config: Config, args: &ArgMatches) -> anyhow::Result<()> {\n    let (command, args) = args.subcommand().context(\"Expected env get or list\")?;\n    let query = match command {\n        \"list\" => Query::List,\n        \"get\" => Query::Get(\n            args.get_one::<String>(\"key\")\n                .context(\"Expected environment key\")?\n                .clone(),\n        ),\n        _ => anyhow::bail!(\"Environment values can only be changed by publishing\"),\n    };\n    query.sql()?;\n    let targets = load_config_db_targets(args.get_flag(\"no_config\"))?;\n    let database = resolve_database_arg(\n        args.get_one::<String>(\"database\").map(String::as_str),\n        targets.as_deref(),\n        \"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> {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/env.rs#L57-L93","documentation":"The `spacetime env` CLI subcommand only supports read-only operations (`list` and `get`). Any other subcommand (e.g. `set`, `unset`) reaches the catch-all arm and is rejected, because environment values are mutated exclusively through the publish flow.","triggerScenarios":"Running `spacetime env set KEY VALUE` (or any verb other than `list`/`get`); typoing a subcommand such as `spacetime env put`.","commonSituations":"Developers expecting shell-like `env set` semantics after deploying; scripts ported from other tools that mutate env vars in place; typos in the env subcommand name.","solutions":["Use `spacetime publish` (with the desired environment values in the config) to change environment values instead of `spacetime env set`.","Check `spacetime env --help` and use only `list` or `get` to read values.","Fix typos in the subcommand verb."],"exampleFix":"// before\nspacetime env set MY_KEY myvalue\n// after\nspacetime publish --project-path . # with MY_KEY set in the environment config","handlingStrategy":"validation","validationCode":"if !matches!(verb.as_str(), \"list\" | \"get\") { eprintln!(\"env values are read-only via `spacetime env`; use `spacetime publish` to change them\"); std::process::exit(2); }","typeGuard":"fn is_readonly_env_query(verb: &str) -> bool { matches!(verb, \"list\" | \"get\") }","tryCatchPattern":null,"preventionTips":["Only use `spacetime env list` / `spacetime env get KEY`; mutate env through publish.","Run `spacetime env --help` to confirm supported verbs before scripting.","Wrap env mutation in the publish pipeline, not ad-hoc commands."],"tags":["cli","environment","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}