{"record":{"id":"1eb2cb90dfc6c960","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-parse-config-file","errorCode":null,"errorMessage":"Failed to parse config file {}: {}","messagePattern":"Failed to parse config file (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/spacetime_config.rs","lineNumber":817,"sourceCode":"    ///\n    /// Searches for spacetime.json starting from `start_dir`\n    /// and walking up the directory tree until found or filesystem root is reached.\n    pub fn find_and_load_from(start_dir: PathBuf) -> anyhow::Result<Option<(PathBuf, Self)>> {\n        Ok(find_and_load_with_env_from(None, start_dir)?.map(|loaded| {\n            let config_path = loaded.config_dir.join(CONFIG_FILENAME);\n            (config_path, loaded.config)\n        }))\n    }\n\n    /// Load a spacetime.json file from a specific path.\n    ///\n    /// The file must exist and be valid JSON5 format (supports comments).\n    pub fn load(path: &Path) -> anyhow::Result<Self> {\n        let content =\n            std::fs::read_to_string(path).with_context(|| format!(\"Failed to read config file: {}\", path.display()))?;\n\n        let config: Self = json5::from_str(&content)\n            .map_err(|e| anyhow::anyhow!(\"Failed to parse config file {}: {}\", path.display(), e))?;\n\n        Ok(config)\n    }\n\n    /// Save the config to a file.\n    ///\n    /// The config will be serialized as pretty-printed JSON.\n    pub fn save(&self, path: &Path) -> anyhow::Result<()> {\n        let json = serde_json::to_string_pretty(self).context(\"Failed to serialize config\")?;\n\n        std::fs::write(path, json).with_context(|| format!(\"Failed to write config file: {}\", path.display()))?;\n\n        Ok(())\n    }\n\n    /// Create a spacetime.json file in the current directory with the given config.\n    pub fn create_in_current_dir(&self) -> anyhow::Result<PathBuf> {\n        let config_path = std::env::current_dir()?.join(\"spacetime.json\");","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/spacetime_config.rs#L799-L835","documentation":"SpacetimeConfig::load read the file successfully but json5::from_str could not parse it: the content is not valid JSON5. Note the file is parsed as JSON5, so comments and trailing commas are legal — the failure means a genuine syntax defect (unbalanced braces/brackets, unterminated string, invalid escape, stray text). The message includes the json5 crate's error, which pinpoints the offending position.","triggerScenarios":"Loading a spacetime.json by explicit path (SpacetimeConfig::load) when the file text has a syntax error; the {e} component carries the parser's line/column detail.","commonSituations":"Hand-editing the config and breaking syntax; unresolved git merge-conflict markers left in the file; templating/snippets inserting stray characters; prose accidentally appended after the closing brace.","solutions":["Open the file and jump to the position reported by the json5 error; fix unbalanced delimiters or quotes and remove conflict markers (<<<<<<< / ======= / >>>>>>>)","Validate the file with a JSON5 linter (e.g. `npx json5 spacetime.json`) to confirm it parses","If the file is beyond repair, regenerate a baseline with `spacetime init` and re-apply your changes incrementally, testing after each edit"],"exampleFix":"// before (spacetime.json)\n{ \"name\": \"mydb\", \"modules\": [ { \"name\": \"m1\" } ]  // missing close for \"modules\"\n\n// after\n{\n  \"name\": \"mydb\",\n  \"modules\": [ { \"name\": \"m1\" } ]\n}","handlingStrategy":"validation","validationCode":"# CI pre-check: reject unparseable config before any spacetime command runs\nnpx --yes json5 spacetime.json > /dev/null || { echo 'spacetime.json is not valid JSON5' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"match SpacetimeConfig::load(&path) {\n    Ok(cfg) => cfg,\n    Err(e) if e.to_string().contains(\"Failed to parse config file\") => {\n        // surface the json5 position from the message; block the pipeline\n        return Err(e.context(\"fix spacetime.json syntax before deploying\"));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Add a JSON5 parse check for spacetime.json to pre-commit hooks and CI","Never commit with merge-conflict markers unresolved; configure the editor to highlight them"],"tags":["spacetimedb","cli","config","json5","parse-error"],"backgroundTag":"config-file-parse-error","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}