Hmbown/CodeWhale · error

failed to parse config TOML while removing plaintext API…

Error message

failed to parse config TOML while removing plaintext API keys; file contents were omitted

What it means

config_toml_without_plaintext_api_keys parses the raw config with toml_edit so plaintext API keys can be removed while preserving comments and layout. If the raw text is not parseable TOML, this sanitized error is thrown instead of exposing the file contents (which would defeat the purpose of removing secrets).

Solutions

  1. Fix the TOML syntax error in the config file
  2. Validate the file with a TOML parser to find the exact line
  3. Restore the config from a backup and re-add settings carefully
  4. Move API keys into the proper secret storage so the scrub path is not needed
Defensive patterns

Strategy: validation

Validate before calling

toml::from_str::<toml::Value>(&raw).map_err(|e| format!("invalid config TOML: {e}"))?;

Try / catch

match scrub_plaintext_keys() {
    Ok(_) => {},
    Err(e) => eprintln!("{e}; fix config TOML syntax, then move keys to secret storage"),
}

Prevention

When it happens

Trigger: Calling config_toml_without_plaintext_api_keys (via the plaintext-key scrubbing path) when the config file contains invalid TOML.

Common situations: A manually edited or corrupted config containing plaintext API keys; a migration/upgrade path that scrubs keys encountering a pre-existing syntax error.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/8bd88fed36c826b3. Report an issue: GitHub.

Appendix: source

Thrown at crates/config/src/lib.rs:5568

            "failed to scrub plaintext API keys while creating config backup {}",
            backup.display()
        )
    })?;
    persistence::atomic_write(&backup, scrubbed.as_bytes()).with_context(|| {
        format!(
            "failed to create credential-free config backup {} from {}",
            backup.display(),
            path.display()
        )
    })?;
    Ok(())
}

fn config_toml_without_plaintext_api_keys(raw: &str) -> Result<String> {
    let mut document = raw
        .parse::<toml_edit::DocumentMut>()
        .map_err(|_| {
            anyhow::anyhow!(
                "failed to parse config TOML while removing plaintext API keys; file contents were omitted"
            )
        })?;
    remove_plaintext_api_keys_recursive(document.as_table_mut());
    Ok(document.to_string())
}

fn remove_plaintext_api_keys_recursive(table: &mut dyn toml_edit::TableLike) {
    table.remove("api_key");
    for (_, item) in table.iter_mut() {
        if let toml_edit::Item::ArrayOfTables(tables) = item {
            for nested in tables.iter_mut() {
                remove_plaintext_api_keys_recursive(nested);
            }
        } else if let Some(nested) = item.as_table_like_mut() {
            remove_plaintext_api_keys_recursive(nested);
        }
    }

View on GitHub (pinned to 73e0f67d83)