xai-org/grok-build · error · io::Error
invalid TOML: {e}
Error message
invalid TOML: {e} What it means
add_marketplace_source parses the existing config file with toml_edit::DocumentMut; if the file is not valid TOML, the parse error is wrapped as std::io::ErrorKind::InvalidData with the message "invalid TOML: {e}" (marketplace.rs:967-972). This prevents appending marketplace sources to a config that would be corrupted further.
Source
Thrown at crates/codegen/xai-grok-shell/src/extensions/marketplace.rs:968
}
}
/// Append a `[[marketplace.sources]]` entry (and optionally set the official
/// flag) in one atomic `toml_edit` write, so a crash can't leave a source
/// without its flag. Idempotent on normalized git URL / local path; preserves
/// comments.
fn add_marketplace_source(
config_path: &std::path::Path,
name: &str,
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()));View on GitHub (pinned to bc7f02eddd)
Solutions
- Run the file through a TOML validator (e.g. `taplo check` or an online parser) and fix the reported syntax error.
- Restore config.toml from backup or version control.
- If regeneration is acceptable, back up and remove the file, then retry adding the marketplace source (config will be recreated).
Example fix
// before: invalid TOML (missing closing quote) [marketplace] name = "official // after: valid TOML [marketplace] name = "official"
Defensive patterns
Strategy: validation
Validate before calling
// validate config.toml parses before invoking marketplace add
let raw = std::fs::read_to_string(&config_path)?;
raw.parse::<toml_edit::DocumentMut>().map_err(|e| format!("config invalid: {e}"))?; Type guard
fn is_valid_toml(path: &std::path::Path) -> bool {
std::fs::read_to_string(path).map(|s| s.parse::<toml_edit::DocumentMut>().is_ok()).unwrap_or(false)
} Try / catch
match add_marketplace_source(&cfg, name, &input, false) {
Err(e) if e.kind() == std::io::ErrorKind::InvalidData && e.to_string().starts_with("invalid TOML") => {
eprintln!("{e}; fix config.toml syntax and retry");
}
other => other,
} Prevention
- Run `taplo check config.toml` (or a TOML linter) after manual edits.
- Keep config.toml under version control to allow easy restores.
- Prefer the CLI's own edit commands over hand-editing.
When it happens
Trigger: Calling add_marketplace_source (via handle_add_source, ensure_official_marketplace_source, or the local-path variant) when config.toml at config_path contains syntactically invalid TOML.
Common situations: Manual editing mistakes in config.toml (unbalanced quotes/brackets, duplicate keys); another tool wrote non-TOML content; truncation from a previous crash; wrong file passed as the config path.
Related errors
- [marketplace] is not a table
- Failed to create agent config: {e}
- Failed to load config: {e}
- Failed to parse config.toml: {e}
- marketplace.sources is not an array of tables
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/060ba986edab9a76.
Report an issue: GitHub.