{"record":{"id":"060ba986edab9a76","repo":"xai-org/grok-build","slug":"invalid-toml-e","errorCode":null,"errorMessage":"invalid TOML: {e}","messagePattern":"invalid TOML: (.+?)","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-shell/src/extensions/marketplace.rs","lineNumber":968,"sourceCode":"    }\n}\n\n/// Append a `[[marketplace.sources]]` entry (and optionally set the official\n/// flag) in one atomic `toml_edit` write, so a crash can't leave a source\n/// without its flag. Idempotent on normalized git URL / local path; preserves\n/// comments.\nfn add_marketplace_source(\n    config_path: &std::path::Path,\n    name: &str,\n    source: &crate::plugin::MarketplaceAddInput,\n    set_official_flag: bool,\n) -> std::io::Result<()> {\n    if let Some(parent) = config_path.parent() {\n        let _ = std::fs::create_dir_all(parent);\n    }\n    let existing = crate::util::config::read_to_string_or_empty(config_path)?;\n    let mut doc = existing.parse::<toml_edit::DocumentMut>().map_err(|e| {\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"invalid TOML: {e}\"),\n        )\n    })?;\n\n    let marketplace_item = doc\n        .entry(\"marketplace\")\n        .or_insert_with(|| toml_edit::Item::Table(toml_edit::Table::new()));\n    let marketplace = marketplace_item.as_table_mut().ok_or_else(|| {\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            \"[marketplace] is not a table\",\n        )\n    })?;\n\n    let sources_item = marketplace\n        .entry(\"sources\")\n        .or_insert_with(|| toml_edit::Item::ArrayOfTables(toml_edit::ArrayOfTables::new()));","sourceCodeStart":950,"sourceCodeEnd":986,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-shell/src/extensions/marketplace.rs#L950-L986","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before: invalid TOML (missing closing quote)\n[marketplace]\nname = \"official\n// after: valid TOML\n[marketplace]\nname = \"official\"","handlingStrategy":"validation","validationCode":"// validate config.toml parses before invoking marketplace add\nlet raw = std::fs::read_to_string(&config_path)?;\nraw.parse::<toml_edit::DocumentMut>().map_err(|e| format!(\"config invalid: {e}\"))?;","typeGuard":"fn is_valid_toml(path: &std::path::Path) -> bool {\n    std::fs::read_to_string(path).map(|s| s.parse::<toml_edit::DocumentMut>().is_ok()).unwrap_or(false)\n}","tryCatchPattern":"match add_marketplace_source(&cfg, name, &input, false) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData && e.to_string().starts_with(\"invalid TOML\") => {\n        eprintln!(\"{e}; fix config.toml syntax and retry\");\n    }\n    other => other,\n}","preventionTips":["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."],"tags":["toml","config","marketplace","file-io"],"backgroundTag":"invalid-toml-config","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}