{"record":{"id":"3c2f92dfefeeaffa","repo":"clockworklabs/SpacetimeDB","slug":"invalid-configuration-structure","errorCode":null,"errorMessage":"Invalid configuration structure","messagePattern":"Invalid configuration structure","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/spacetime_config/environment.rs","lineNumber":100,"sourceCode":"    for (index, (start, end)) in replacements.into_iter().enumerate() {\n        text.push_str(&content[previous..start]);\n        text.push_str(&format!(\"\\\"{prefix}{index}\\\"\"));\n        previous = end;\n    }\n    text.push_str(&content[previous..]);\n    // Parser diagnostics may quote the source line, which can contain secrets.\n    let mut value: Value = json5::from_str(&text).map_err(|_| anyhow::anyhow!(\"Invalid JSON5 configuration\"))?;\n    restore(&mut value, &prefix, &numbers, None)?;\n    Ok(value)\n}\n\n/// Deserialize through JSON text so Serde's flattened-field buffer does not\n/// receive visit_u128 from Value's deserializer. That buffer cannot represent\n/// u128, while the arbitrary-precision JSON parser preserves its decimal token.\n/// Diagnostics discard values while retaining a bounded, ordinary unknown field\n/// name, which is useful for correcting misspelled configuration options.\npub(super) fn decode_config(value: Value) -> anyhow::Result<super::SpacetimeConfig> {\n    let encoded = serde_json::to_vec(&value).map_err(|_| anyhow::anyhow!(\"Invalid configuration structure\"))?;\n    serde_json::from_slice(&encoded).map_err(|error| {\n        let diagnostic = error.to_string();\n        if let Some((field, suffix)) = diagnostic\n            .strip_prefix(\"unknown field `\")\n            .and_then(|message| message.split_once('`'))\n            && suffix.starts_with(\", expected \")\n            && !field.is_empty()\n            && field.len() <= 64\n            && field\n                .bytes()\n                .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'-'))\n        {\n            return anyhow::anyhow!(\"unknown field `{field}`\");\n        }\n        anyhow::anyhow!(\"Invalid configuration structure\")\n    })\n}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/spacetime_config/environment.rs#L82-L118","documentation":"`decode_config` re-serializes the parsed JSON Value and deserializes it into `SpacetimeConfig`. If serialization of the Value itself fails (a degenerate/invalid Value), the error is this opaque message, again avoiding echoing config contents that may hold secrets.","triggerScenarios":"A parsed Value that `serde_json::to_vec` cannot encode (e.g. non-string map keys or NaN/floating values not representable in JSON), passed through the environment config decode path.","commonSituations":"Config files with JSON5 extensions that produce Values outside strict JSON; exotic numeric inputs like NaN or Infinity at the top level of the config.","solutions":["Replace NaN/Infinity or other non-JSON values in the config with valid JSON numbers or strings.","Simplify the config structure to plain JSON-compatible objects, arrays, strings, numbers, booleans.","Update the CLI if this occurs with an apparently normal config, and report it as a bug."],"exampleFix":"// before (config)\nRATIO: NaN\n// after (config)\nRATIO: 0","handlingStrategy":"validation","validationCode":"fn is_json_encodable(v: &serde_json::Value) -> bool { !matches!(v, serde_json::Value::Number(n) if n.as_f64().map_or(false, |f| f.is_nan() || f.is_infinite())) }","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string() == \"Invalid configuration structure\" => { eprintln!(\"Config Value is not JSON-encodable; remove NaN/Infinity or exotic values\"); }, Err(e) => return Err(e), Ok(v) => v }","preventionTips":["Avoid NaN/Infinity and other non-JSON values in config files.","Keep config structure to plain JSON-compatible types.","Report reproducible failures on normal configs as CLI bugs."],"tags":["config","serde","validation"],"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"}