{"record":{"id":"6cd4613e38c39031","repo":"clockworklabs/SpacetimeDB","slug":"environment-key-numeric-config-input-must-use-json-number","errorCode":null,"errorMessage":"Environment key {:?}: numeric config input must use JSON number syntax","messagePattern":"Environment key (.+?): numeric config input must use JSON number syntax","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/spacetime_config/environment.rs","lineNumber":130,"sourceCode":"        {\n            return anyhow::anyhow!(\"unknown field `{field}`\");\n        }\n        anyhow::anyhow!(\"Invalid configuration structure\")\n    })\n}\n\nfn is_space(ch: char) -> bool {\n    ch.is_whitespace() || ch == '\\u{feff}'\n}\n\nfn restore(value: &mut Value, prefix: &str, numbers: &[&str], env_key: Option<&str>) -> anyhow::Result<()> {\n    match value {\n        Value::String(s) => {\n            if let Some(index) = s.strip_prefix(prefix).and_then(|s| s.parse::<usize>().ok()) {\n                let token = numbers[index];\n                *value = if let Some(env_key) = env_key {\n                    Value::Number(token.parse().map_err(|_| {\n                        anyhow::anyhow!(\n                            \"Environment key {:?}: numeric config input must use JSON number syntax\",\n                            env_key\n                        )\n                    })?)\n                } else {\n                    // Preserve existing JSON5 conveniences outside env. JSON numbers retain\n                    // arbitrary precision throughout layering and config serialization.\n                    token\n                        .parse()\n                        .map(Value::Number)\n                        .or_else(|_| json5::from_str(token))\n                        .map_err(|_| anyhow::anyhow!(\"Invalid numeric configuration input\"))?\n                };\n            }\n        }\n        Value::Object(object) => {\n            for (key, value) in object {\n                if key == \"env\" && env_key.is_none() {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/spacetime_config/environment.rs#L112-L148","documentation":"During parsing, numeric tokens (including JSON5 hex/octal/big numbers) are masked with placeholder strings and restored afterwards. Inside an environment entry (`env_key` set), the token must parse as a JSON number; if it does not (e.g. JSON5-only syntax like `0xFF` used as an env value), `restore` fails naming the environment key.","triggerScenarios":"An env config value written with JSON5 numeric extensions such as `0x1F`, `1_000`, or a leading `+`, which are not valid JSON number syntax and thus rejected for environment values.","commonSituations":"Using JavaScript-style hex or underscore-separated literals in spacetimedb config env values; values intended as strings (e.g. IDs with leading zeros) parsed as numbers.","solutions":["Rewrite the value using strict JSON number syntax (e.g. `31` instead of `0x1F`).","Quote the value as a string if the exact token text matters (e.g. `\"0x1F\"`).","Remove underscores/plus signs from numeric env values."],"exampleFix":"// before (config env)\nPORT: 0x1F90\n// after (config env)\nPORT: 8080","handlingStrategy":"validation","validationCode":"fn is_json_number_literal(tok: &str) -> bool { tok.parse::<serde_json::Number>().is_ok() } // rejects 0x1F, 1_000, +5","typeGuard":"fn is_strict_json_number(s: &str) -> bool { s.parse::<f64>().is_ok() && !s.starts_with('+') && !s.contains('_') && !s.starts_with(\"0x\") }","tryCatchPattern":"match result { Err(e) if e.to_string().contains(\"numeric config input must use JSON number syntax\") => { eprintln!(\"Rewrite the named env key's value as a JSON number or quote it as a string\"); }, Err(e) => return Err(e), Ok(v) => v }","preventionTips":["Use decimal JSON numbers only in env values — no hex, octal, underscores, or leading `+`.","Quote values like `\"0x1F\"` if the literal text matters.","Keep env keys string-or-decimal-number only."],"tags":["config","environment","numbers","json5"],"backgroundTag":"invalid-config-value","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"}