xai-org/grok-build · error · io::Error

[marketplace] is not a table

Error message

[marketplace] is not a table

What it means

add_marketplace_source inserts-or-fetches the `marketplace` key and calls as_table_mut; if that entry exists but is not a TOML table (e.g. it's a string, integer, or array), the write aborts with ErrorKind::InvalidData and message "[marketplace] is not a table" (marketplace.rs:977-982). The code cannot attach [[marketplace.sources]] to a non-table value.

Source

Thrown at crates/codegen/xai-grok-shell/src/extensions/marketplace.rs:978

    source: &crate::plugin::MarketplaceAddInput,
    set_official_flag: bool,
) -> std::io::Result<()> {
    if let Some(parent) = config_path.parent() {
        let _ = std::fs::create_dir_all(parent);
    }
    let existing = crate::util::config::read_to_string_or_empty(config_path)?;
    let mut doc = existing.parse::<toml_edit::DocumentMut>().map_err(|e| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidData,
            format!("invalid TOML: {e}"),
        )
    })?;

    let marketplace_item = doc
        .entry("marketplace")
        .or_insert_with(|| toml_edit::Item::Table(toml_edit::Table::new()));
    let marketplace = marketplace_item.as_table_mut().ok_or_else(|| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidData,
            "[marketplace] is not a table",
        )
    })?;

    let sources_item = marketplace
        .entry("sources")
        .or_insert_with(|| toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new()));
    let sources = sources_item.as_array_of_tables_mut().ok_or_else(|| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidData,
            "[[marketplace.sources]] is not an array of tables",
        )
    })?;

    // Skip if the normalized URL / path already exists: the pre-lock dup check
    // in handle_add_source can let two serialized adds reach here.
    use crate::plugin::MarketplaceAddInput;

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Open config.toml and change the `marketplace` entry to a table: `[marketplace]` (remove the scalar/array assignment).
  2. Migrate old-format settings into the table form, e.g. move values under [marketplace] and sources under [[marketplace.sources]].
  3. Back up the file first so the migration can be reverted if other tooling depended on the old shape.

Example fix

// before: wrong shape
marketplace = "official"
// after: table shape expected by the tool
[marketplace]
[[marketplace.sources]]
name = "official"
url = "https://github.com/example/marketplace"
Defensive patterns

Strategy: validation

Validate before calling

// ensure `marketplace` is a table before appending sources
let doc = raw.parse::<toml_edit::DocumentMut>()?;
if let Some(item) = doc.get("marketplace") {
    if item.as_table().is_none() && !item.is_none() {
        eprintln!("config: `marketplace` must be a table, found another type");
    }
}

Type guard

fn marketplace_is_table(doc: &toml_edit::DocumentMut) -> bool {
    doc.get("marketplace").map_or(true, |i| i.as_table().is_some())
}

Try / catch

match add_marketplace_source(&cfg, name, &input, false) {
    Err(e) if e.to_string().contains("[marketplace] is not a table") => {
        eprintln!("fix config: replace scalar `marketplace = ...` with a [marketplace] table");
    }
    other => other,
}

Prevention

When it happens

Trigger: config.toml already defines `marketplace` as a scalar or array (e.g. `marketplace = "x"` or `marketplace = [1]`) when add_marketplace_source runs.

Common situations: Hand-edited config using the wrong shape for the marketplace key; older config format where `marketplace` was a plain value; copy-paste from docs of a different tool.

Related errors


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