{"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":"exception","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/6dee26c6efc2856793e12b148a59742964f5d783/crates/cli/src/spacetime_config.rs#L799-L835","documentation":"SpacetimeConfig::load (crates/cli/src/spacetime_config.rs:817) reads a spacetime.json file (JSON5, so comments and trailing commas are tolerated) and maps json5::from_str failures to this error with the file path and the underlying json5 error (line/column and reason). It is the strict 'load this exact path' entry point, used when a specific config file is requested rather than discovered.","triggerScenarios":"Passing a spacetime.json containing JSON5 syntax errors: unclosed braces, smart quotes pasted from a word processor, unquoted keys with invalid characters, trailing garbage after the top-level object, or a BOM prepended by some editors.","commonSituations":"Hand-editing generated config files; merging config changes in git and resolving conflicts badly (leftover <<<<<<< markers are not comments); templating configs with unescaped placeholders.","solutions":["Open the file at the line/column reported by the json5 error and fix the syntax it names (unclosed bracket, bad token).","Validate the file standalone, e.g. `npx json5 spacetime.json` or any JSON5 linter, before rerunning the CLI.","If you don't need JSON5 features, strip comments/trailing commas and validate as strict JSON with `jq . spacetime.json`.","Check for merge-conflict markers and smart quotes after git merges or copy-paste."],"exampleFix":"// before: spacetime.json\n{\n  \"name\": \"mydb\",   // trailing: missing closing brace\n// after\n{\n  \"name\": \"mydb\"\n}","handlingStrategy":"validation","validationCode":"// CI gate: parse every spacetime.json as JSON5 before any spacetime CLI runs.\nfn check(path: &Path) {\n    let src = std::fs::read_to_string(path).unwrap();\n    json5::from_str::<serde_json::Value>(&src)\n        .unwrap_or_else(|e| panic!(\"{}: invalid JSON5: {e}\", path.display()));\n}\n// shell equivalent: npx --yes json5 spacetime.json > /dev/null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a JSON5 linter on spacetime.json in a pre-commit hook and in CI.","After git merges on config files, grep for conflict markers (<<<<<<< / >>>>>>>) - they are not JSON5 comments.","Prefer strict JSON (no comments) if your tooling templating is JSON-native; JSON5 support exists for humans, not templaters."],"tags":["spacetimedb","cli","config","json5","parse-error"],"backgroundTag":"config-file-parse-error","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}