xai-org/grok-build · error
refusing to rewrite unparseable {}: {e}
Error message
refusing to rewrite unparseable {}: {e} What it means
clear_sticky_project_disabled_at uses toml_edit::DocumentMut so comments and formatting survive edits. If the existing file fails to parse as TOML, the library refuses to rewrite it — deliberately avoiding destroying a hand-maintained (or partially corrupted) config, and instead throws this error naming the file and parse error.
Source
Thrown at crates/codegen/xai-grok-shell/src/util/config/mcp.rs:827
.map_err(|e| anyhow::anyhow!("failed to write {}: {e}", path.display()))?;
Ok(true)
}
/// Flip sticky project `enabled = false` → true with toml_edit (comments kept).
async fn clear_sticky_project_disabled_at(
path: &std::path::Path,
server_name: &str,
) -> Result<bool> {
let original = match tokio::fs::read_to_string(path).await {
Ok(s) => s,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(false),
Err(e) => {
return Err(anyhow::anyhow!("failed to read {}: {e}", path.display()));
}
};
let mut doc: toml_edit::DocumentMut = original
.parse()
.map_err(|e| anyhow::anyhow!("refusing to rewrite unparseable {}: {e}", path.display()))?;
let Some(servers) = doc
.get_mut("mcp_servers")
.and_then(|item| item.as_table_like_mut())
else {
return Ok(false);
};
let Some(entry) = servers.get_mut(server_name) else {
return Ok(false);
};
let Some(server_table) = entry.as_table_like_mut() else {
return Ok(false);
};
if server_table.get("enabled").and_then(|v| v.as_bool()) != Some(false) {
return Ok(false);
}
server_table.insert("enabled", toml_edit::value(true));
View on GitHub (pinned to bc7f02eddd)
Solutions
- Run a TOML linter/parser on the file and fix the reported syntax error
- Remove merge-conflict markers or restore the file from version control
- If the file is disposable, delete it and let the tool regenerate a clean config
- Re-run the command once the file parses
Example fix
// before (config.toml) <<<<<<< HEAD [mcp_servers.foo] // after (config.toml) [mcp_servers.foo] enabled = false
Defensive patterns
Strategy: validation
Validate before calling
// validate before letting toml_edit touch the file
let src = std::fs::read_to_string(path)?;
if src.contains("<<<<<<<") {
return Err("merge conflict markers in config".into());
}
let _doc: toml_edit::DocumentMut = src.parse().map_err(|e| format!("invalid TOML: {e}"))?; Type guard
fn parses_as_toml(src: &str) -> bool {
src.parse::<toml_edit::DocumentMut>().is_ok()
} Try / catch
match result {
Err(e) if e.to_string().starts_with("refusing to rewrite unparseable") => {
eprintln!("fix TOML syntax in the named file or restore from VCS: {e}");
}
r => r?,
} Prevention
- Run a TOML linter after every manual config edit
- Resolve merge conflicts in config files before running the tool
- Keep configs in git so broken edits can be reverted
When it happens
Trigger: save_mcp_server_enabled_in / enable_unstick_only_touches_nearest_project_definition / restore_mcp_server_enabled_after_enable_scopes_tiers encounter a project config file containing invalid TOML (unclosed string, duplicate key, bad syntax).
Common situations: Manual edits with typos; a merge conflict marker left in the file (<<<<<<<); truncated write from a crash; an editor saving non-UTF8 or garbled content.
Related errors
- Failed to parse config.toml: {e}
- refusing to write import marker: existing config at {} is no
- refusing to import: existing config at {} is not valid TOML
- refusing to overwrite unparseable {}: {}; fix the syntax bef
- refusing to overwrite unparseable {}: {}; save a backup and
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/28c2d918de1abe96.
Report an issue: GitHub.