{"record":{"id":"00ccdb4f287de6c6","repo":"xai-org/grok-build","slug":"marketplace-sources-is-not-an-array-of-tables","errorCode":null,"errorMessage":"marketplace.sources is not an array of tables","messagePattern":"marketplace\\.sources is not an array of tables","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/plugin_cmd.rs","lineNumber":928,"sourceCode":"    };\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);\n        }\n        MarketplaceAddInput::LocalPath(path) => {\n            entry[\"path\"] = toml_edit::value(path.display().to_string());\n        }\n    }\n    sources.push(entry);\n\n    std::fs::write(&config_path, doc.to_string())?;\n\n    println!(\"Added marketplace source: {name} ({identity})\");\n    Ok(())\n}","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/plugin_cmd.rs#L910-L946","documentation":"After parsing config.toml, the code expects `marketplace.sources` to be an Array of Tables (i.e. `[[marketplace.sources]]` entries). If the key exists but has a different TOML type (a plain table, string, or inline array), `as_array_of_tables_mut()` returns None and this error is raised instead of the code silently replacing the user's data.","triggerScenarios":"Running `grok plugin marketplace add` when config.toml contains `marketplace.sources` defined as something other than `[[...]]` array-of-tables — e.g. `sources = \"x\"`, `sources = { }`, or an inline array `sources = [...]`.","commonSituations":"User hand-wrote `sources = []` or a single `[marketplace.sources]` non-list form; a different tool migrated the config to a different shape; older config format from a previous version of grok.","solutions":["Edit config.toml and change `marketplace.sources` to array-of-tables form: `[[marketplace.sources]]` blocks","Or remove the `sources` key entirely and re-run the add command (it will recreate it correctly)","Back up config.toml before editing"],"exampleFix":"// before (config.toml)\n[marketplace]\nsources = []\n// after\n[marketplace]\n[[marketplace.sources]]\nname = \"example\"\ngit = \"https://example.com/repo.git\"","handlingStrategy":"type-guard","validationCode":"let content = std::fs::read_to_string(&config_path)?;\nlet doc = content.parse::<toml_edit::DocumentMut>()?;\nlet is_aot = doc.get(\"marketplace\")\n    .and_then(|m| m.get(\"sources\"))\n    .map(|s| s.as_array_of_tables().is_some())\n    .unwrap_or(true); // absent is fine\nif !is_aot { eprintln!(\"marketplace.sources must be [[marketplace.sources]] blocks\"); }","typeGuard":"fn sources_is_array_of_tables(doc: &toml_edit::DocumentMut) -> bool {\n    doc.get(\"marketplace\")\n        .and_then(|m| m.get(\"sources\"))\n        .map(|s| s.as_array_of_tables().is_some())\n        .unwrap_or(true)\n}","tryCatchPattern":"match doc[\"marketplace\"][\"sources\"].as_array_of_tables_mut() {\n    Some(sources) => sources.push(entry),\n    None => eprintln!(\"config.toml: marketplace.sources has wrong type; use [[marketplace.sources]]\"),\n}","preventionTips":["Write sources as [[marketplace.sources]] table blocks, never `sources = []` or `sources = \"...\"`","Validate config.toml with a TOML linter after manual edits","Let grok create the sources key the first time rather than pre-creating it"],"tags":["config","toml","type-mismatch"],"backgroundTag":"config-type-mismatch","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}