xai-org/grok-build · error

Failed to parse config.toml: {e}

Error message

Failed to parse config.toml: {e}

What it means

When adding a marketplace source, the command reads `~/.grok/config.toml` (or the configured grok home) and parses it with `toml_edit::DocumentMut`. If the existing file contains invalid TOML, the parse fails and the add is aborted rather than silently overwriting the user's config.

Source

Thrown at crates/codegen/xai-grok-pager/src/plugin_cmd.rs:916

    if !force && let MarketplaceAddInput::GitUrl(git_url) = &input {
        xai_grok_plugin_marketplace::git::probe_git_remote(git_url).map_err(|e| {
            anyhow::anyhow!(
                "{e}\nNot adding \"{url}\": it doesn't look like a reachable git repository. \
                 Re-run with --force to add it anyway (e.g. a host only reachable on VPN)."
            )
        })?;
    }

    let name = match &input {
        MarketplaceAddInput::GitUrl(u) => plugin::name_from_url(u),
        MarketplaceAddInput::LocalPath(p) => plugin::name_from_path(p),
    };
    let config_path = xai_grok_config::grok_home().join(xai_grok_config::USER_CONFIG_FILENAME);

    let content = std::fs::read_to_string(&config_path).unwrap_or_default();
    let mut doc: toml_edit::DocumentMut = content
        .parse()
        .map_err(|e| anyhow::anyhow!("Failed to parse config.toml: {e}"))?;

    if doc.get("marketplace").is_none() {
        doc["marketplace"] = toml_edit::Item::Table(toml_edit::Table::new());
    }
    if doc["marketplace"].get("sources").is_none() {
        doc["marketplace"]["sources"] =
            toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new());
    }

    let sources = doc["marketplace"]["sources"]
        .as_array_of_tables_mut()
        .ok_or_else(|| anyhow::anyhow!("marketplace.sources is not an array of tables"))?;

    let mut entry = toml_edit::Table::new();
    entry["name"] = toml_edit::value(&name);
    match &input {
        MarketplaceAddInput::GitUrl(git_url) => {
            entry["git"] = toml_edit::value(git_url);

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Open the config.toml path shown/implied and fix the TOML syntax error described by `{e}` (line/col usually included)
  2. Validate the file with a TOML linter or `toml_edit`/`taplo` check
  3. Restore from backup or `git` history if the file was corrupted by a tool
  4. Re-run the marketplace add command

Example fix

// before (config.toml)
[marketplace
name = "x"
// after
[marketplace]
name = "x"
Defensive patterns

Strategy: validation

Validate before calling

let content = std::fs::read_to_string(&config_path).unwrap_or_default();
if let Err(e) = content.parse::<toml_edit::DocumentMut>() {
    eprintln!("fix config.toml before running marketplace commands: {e}");
}

Try / catch

match content.parse::<toml_edit::DocumentMut>() {
    Ok(mut doc) => { /* proceed */ }
    Err(e) => eprintln!("config.toml is invalid TOML ({e}); fix or restore it"),
}

Prevention

When it happens

Trigger: Running any `grok plugin marketplace add ...` while the user's config.toml has a TOML syntax error (unclosed string/bracket, duplicate keys invalid to toml_edit, stray characters). Missing file is fine (empty default), only unparseable content triggers this.

Common situations: Manual edits to config.toml breaking syntax; another tool writing the file concurrently and truncating it; pasting JSON into the TOML file; merge-conflict markers left in the file.

Understand the failure class

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/dcd4d5c719e16c18. Report an issue: GitHub.