clockworklabs/SpacetimeDB · error

Failed to parse config file

Error message

Failed to parse config file {}: {}

What it means

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.

Solutions

  1. Open the file at the line/column reported by the json5 error and fix the syntax it names (unclosed bracket, bad token).
  2. Validate the file standalone, e.g. `npx json5 spacetime.json` or any JSON5 linter, before rerunning the CLI.
  3. If you don't need JSON5 features, strip comments/trailing commas and validate as strict JSON with `jq . spacetime.json`.
  4. Check for merge-conflict markers and smart quotes after git merges or copy-paste.

Example fix

// before: spacetime.json
{
  "name": "mydb",   // trailing: missing closing brace
// after
{
  "name": "mydb"
}
Defensive patterns

Strategy: validation

Validate before calling

// CI gate: parse every spacetime.json as JSON5 before any spacetime CLI runs.
fn check(path: &Path) {
    let src = std::fs::read_to_string(path).unwrap();
    json5::from_str::<serde_json::Value>(&src)
        .unwrap_or_else(|e| panic!("{}: invalid JSON5: {e}", path.display()));
}
// shell equivalent: npx --yes json5 spacetime.json > /dev/null

Prevention

When it happens

Trigger: 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.

Common situations: Hand-editing generated config files; merging config changes in git and resolving conflicts badly (leftover <<<<<<< markers are not comments); templating configs with unescaped placeholders.

Understand the failure class

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/1eb2cb90dfc6c960. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/spacetime_config.rs:817

    ///
    /// Searches for spacetime.json starting from `start_dir`
    /// and walking up the directory tree until found or filesystem root is reached.
    pub fn find_and_load_from(start_dir: PathBuf) -> anyhow::Result<Option<(PathBuf, Self)>> {
        Ok(find_and_load_with_env_from(None, start_dir)?.map(|loaded| {
            let config_path = loaded.config_dir.join(CONFIG_FILENAME);
            (config_path, loaded.config)
        }))
    }

    /// Load a spacetime.json file from a specific path.
    ///
    /// The file must exist and be valid JSON5 format (supports comments).
    pub fn load(path: &Path) -> anyhow::Result<Self> {
        let content =
            std::fs::read_to_string(path).with_context(|| format!("Failed to read config file: {}", path.display()))?;

        let config: Self = json5::from_str(&content)
            .map_err(|e| anyhow::anyhow!("Failed to parse config file {}: {}", path.display(), e))?;

        Ok(config)
    }

    /// Save the config to a file.
    ///
    /// The config will be serialized as pretty-printed JSON.
    pub fn save(&self, path: &Path) -> anyhow::Result<()> {
        let json = serde_json::to_string_pretty(self).context("Failed to serialize config")?;

        std::fs::write(path, json).with_context(|| format!("Failed to write config file: {}", path.display()))?;

        Ok(())
    }

    /// Create a spacetime.json file in the current directory with the given config.
    pub fn create_in_current_dir(&self) -> anyhow::Result<PathBuf> {
        let config_path = std::env::current_dir()?.join("spacetime.json");

View on GitHub (pinned to 6dee26c6ef)