clockworklabs/SpacetimeDB · error
Failed to parse config file {}: {}
Error message
Failed to parse config file {}: {} What it means
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.
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 524b4487d9)
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
Example fix
// before (spacetime.json)
{ "name": "mydb", "modules": [ { "name": "m1" } ] // missing close for "modules"
// after
{
"name": "mydb",
"modules": [ { "name": "m1" } ]
} Defensive patterns
Strategy: validation
Validate before calling
# CI pre-check: reject unparseable config before any spacetime command runs
npx --yes json5 spacetime.json > /dev/null || { echo 'spacetime.json is not valid JSON5' >&2; exit 1; } Try / catch
match SpacetimeConfig::load(&path) {
Ok(cfg) => cfg,
Err(e) if e.to_string().contains("Failed to parse config file") => {
// surface the json5 position from the message; block the pipeline
return Err(e.context("fix spacetime.json syntax before deploying"));
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Cannot use module-specific arguments ({}) when {}. {}
- spacetime.json not found in {}
- Database '{}' is not in the config file. If you want to run
- Unsupported --dotnet-version {version}. Supported values: 8,
- No such saved server configuration: {server} Add a new serve
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/1eb2cb90dfc6c960.
Report an issue: GitHub.