Hmbown/CodeWhale · error

failed to parse config at {}; file contents were omitted

Error message

failed to parse config at {}; file contents were omitted

What it means

The /network command loads the TOML config via load_config_doc before editing it. If the file exists but toml::from_str fails, it errors with 'failed to parse config at <path>'; file contents are deliberately omitted (crates/tui/src/commands/groups/utility/network.rs:189) because the config may contain secrets.

Source

Thrown at crates/tui/src/commands/groups/utility/network.rs:189

    crate::config_persistence::mutate_config_document(&path, |doc| {
        ensure_network_defaults(doc)?;
        crate::config_persistence::set_document_value(doc, &["network", "default"], normalized)
    })?;

    Ok(format!(
        "Network default set to {normalized}\nSaved to {}.",
        path.display()
    ))
}

fn load_config_doc(path: &Path) -> anyhow::Result<Value> {
    if !path.exists() {
        return Ok(Value::Table(toml::value::Table::new()));
    }
    let raw = fs::read_to_string(path)
        .with_context(|| format!("failed to read config at {}", path.display()))?;
    toml::from_str(&raw).map_err(|_| {
        anyhow::anyhow!(
            "failed to parse config at {}; file contents were omitted",
            codewhale_config::quote_os_path(path)
        )
    })
}

fn ensure_network_defaults(doc: &mut toml_edit::DocumentMut) -> anyhow::Result<()> {
    if doc
        .get("network")
        .and_then(toml_edit::Item::as_table_like)
        .and_then(|table| table.get("default"))
        .is_none()
    {
        crate::config_persistence::set_document_value(doc, &["network", "default"], "prompt")?;
    }
    if doc
        .get("network")
        .and_then(toml_edit::Item::as_table_like)

View on GitHub (pinned to 8880682c63)

Solutions

  1. Validate the file: python3 -c "import tomllib,sys; tomllib.load(open(sys.argv[1],'rb'))" <path>
  2. Fix duplicate keys, unclosed quotes/brackets, and smart-quote characters around recent edits
  3. Restore the file from backup or git history and reapply only the intended change
  4. Retry the /network command once the file parses

Example fix

# config.toml - before
[network]
default = "kimi   # unclosed string, parse fails

# config.toml - after
[network]
default = "kimi"
Defensive patterns

Strategy: validation

Validate before calling

# Before running /network, prove the file parses
python3 -c "import tomllib,sys; tomllib.load(open(sys.argv[1],'rb'))" ~/.codewhale/config.toml && echo OK

Try / catch

// In Rust: parse-or-refuse before editing
let doc: toml::Value = toml::from_str(&raw)
    .map_err(|e| anyhow::anyhow!("config unparseable, refusing edit: {e}"))?;

Prevention

When it happens

Trigger: A hand-edited config with an unclosed string, duplicate key, or missing bracket; a bad merge-conflict resolution; a BOM or smart quotes inserted by an editor; a file truncated by a crash during save.

Common situations: Editing config.toml in a new editor that auto-inserts smart quotes or CRLF; git merge artifacts; multi-tool setups where another tool rewrote the file.

Understand the failure class

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/54771edee6c6dd5f. Report an issue: GitHub.