{"record":{"id":"36ae4b90a45a3e2d","repo":"clockworklabs/SpacetimeDB","slug":"too-many-environment-removals","errorCode":null,"errorMessage":"Too many environment removals","messagePattern":"Too many environment removals","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/publish.rs","lineNumber":372,"sourceCode":"\n#[derive(Default)]\nstruct EnvironmentOptions {\n    only: bool,\n    remove: Vec<String>,\n    replace: bool,\n}\n\nimpl EnvironmentOptions {\n    fn from_args(args: &ArgMatches) -> anyhow::Result<Self> {\n        let options = Self {\n            only: args.get_flag(\"env_only\"),\n            remove: args\n                .get_many::<String>(\"unset_env\")\n                .map(|keys| keys.cloned().collect())\n                .unwrap_or_default(),\n            replace: args.get_flag(\"replace_env\"),\n        };\n        ensure!(\n            options.remove.len() <= spacetimedb_lib::environment::MAX_ENV_VARS,\n            \"Too many environment removals\"\n        );\n        for key in &options.remove {\n            spacetimedb_lib::environment::validate_key(key)?;\n        }\n        Ok(options)\n    }\n\n    fn validate_values(&self, values: &std::collections::BTreeMap<String, String>) -> anyhow::Result<()> {\n        ensure!(\n            !self.replace || self.remove.is_empty(),\n            \"--replace-env cannot be combined with --unset-env\"\n        );\n        for key in &self.remove {\n            ensure!(\n                !values.contains_key(key),\n                \"Environment key {key:?} is both supplied and removed\"","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/publish.rs#L354-L390","documentation":"Thrown by `from_args` in crates/cli/src/subcommands/publish.rs when `spacetime publish` is invoked with more `--unset-env` keys than `spacetimedb_lib::environment::MAX_ENV_VARS`. The removal list is validated before any keys are sent to the server.","triggerScenarios":"A publish command passes a very long list of `--unset-env KEY` flags such that `options.remove.len() > MAX_ENV_VARS` — usually from a generated/scripted command line with hundreds of unset flags.","commonSituations":"Auto-generated deploy scripts that enumerate every previously-set key for removal; batch migrations clearing large inherited environments; shell expansion mistakes duplicating flags.","solutions":["Reduce the number of `--unset-env` flags to at most MAX_ENV_VARS per publish.","Recreate the environment (publish fresh) instead of unsetting every key individually.","Fix the generating script to deduplicate and cap the removal list.","If wholesale clearing is intended, unset keys across multiple publishes."],"exampleFix":"// before\nspacetime publish my-db --unset-env K1 --unset-env K2 ... # 300 flags\n// after\nspacetime publish my-db --replace-env   # or unset in batches of <= MAX_ENV_VARS","handlingStrategy":"validation","validationCode":"// cap removal list before building the publish command\nif keys_to_unset.len() > spacetimedb_lib::environment::MAX_ENV_VARS {\n    return Err(\"too many env removals for one publish\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate removal lists in generated publish scripts.","Use --replace-env for wholesale clearing instead of many --unset-env flags.","Split large cleanups across multiple publishes."],"tags":["cli","spacetimedb","limits","publish"],"backgroundTag":"value-out-of-range","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"}