{"record":{"id":"dcd4d5c719e16c18","repo":"xai-org/grok-build","slug":"failed-to-parse-config-toml-e","errorCode":null,"errorMessage":"Failed to parse config.toml: {e}","messagePattern":"Failed to parse config\\.toml: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/plugin_cmd.rs","lineNumber":916,"sourceCode":"    if !force && let MarketplaceAddInput::GitUrl(git_url) = &input {\n        xai_grok_plugin_marketplace::git::probe_git_remote(git_url).map_err(|e| {\n            anyhow::anyhow!(\n                \"{e}\\nNot adding \\\"{url}\\\": it doesn't look like a reachable git repository. \\\n                 Re-run with --force to add it anyway (e.g. a host only reachable on VPN).\"\n            )\n        })?;\n    }\n\n    let name = match &input {\n        MarketplaceAddInput::GitUrl(u) => plugin::name_from_url(u),\n        MarketplaceAddInput::LocalPath(p) => plugin::name_from_path(p),\n    };\n    let config_path = xai_grok_config::grok_home().join(xai_grok_config::USER_CONFIG_FILENAME);\n\n    let content = std::fs::read_to_string(&config_path).unwrap_or_default();\n    let mut doc: toml_edit::DocumentMut = content\n        .parse()\n        .map_err(|e| anyhow::anyhow!(\"Failed to parse config.toml: {e}\"))?;\n\n    if doc.get(\"marketplace\").is_none() {\n        doc[\"marketplace\"] = toml_edit::Item::Table(toml_edit::Table::new());\n    }\n    if doc[\"marketplace\"].get(\"sources\").is_none() {\n        doc[\"marketplace\"][\"sources\"] =\n            toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new());\n    }\n\n    let sources = doc[\"marketplace\"][\"sources\"]\n        .as_array_of_tables_mut()\n        .ok_or_else(|| anyhow::anyhow!(\"marketplace.sources is not an array of tables\"))?;\n\n    let mut entry = toml_edit::Table::new();\n    entry[\"name\"] = toml_edit::value(&name);\n    match &input {\n        MarketplaceAddInput::GitUrl(git_url) => {\n            entry[\"git\"] = toml_edit::value(git_url);","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/plugin_cmd.rs#L898-L934","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the config.toml path shown/implied and fix the TOML syntax error described by `{e}` (line/col usually included)","Validate the file with a TOML linter or `toml_edit`/`taplo` check","Restore from backup or `git` history if the file was corrupted by a tool","Re-run the marketplace add command"],"exampleFix":"// before (config.toml)\n[marketplace\nname = \"x\"\n// after\n[marketplace]\nname = \"x\"","handlingStrategy":"validation","validationCode":"let content = std::fs::read_to_string(&config_path).unwrap_or_default();\nif let Err(e) = content.parse::<toml_edit::DocumentMut>() {\n    eprintln!(\"fix config.toml before running marketplace commands: {e}\");\n}","typeGuard":null,"tryCatchPattern":"match content.parse::<toml_edit::DocumentMut>() {\n    Ok(mut doc) => { /* proceed */ }\n    Err(e) => eprintln!(\"config.toml is invalid TOML ({e}); fix or restore it\"),\n}","preventionTips":["Never hand-edit config.toml without re-parsing/validating afterward","Keep config.toml under version control for easy restore","Avoid editing config.toml while a grok process is running"],"tags":["config","toml","parse-error"],"backgroundTag":"config-parse-error","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}