Hmbown/CodeWhale · error

Failed to parse config from

Error message

Failed to parse config from {}; file contents were omitted

What it means

During logout, the persisted config.toml is re-read and re-parsed to inspect whether `custom` refers to the legacy root-shaped route or a [providers.custom] table, so logout clears exactly the right credential scope. If toml::from_str::<Config> fails, this error is thrown with the OS-quoted path but the file contents deliberately omitted, since the file may contain private text.

Solutions

  1. Open the quoted config path and fix the TOML syntax/fields so it parses as Config (run the app or a TOML linter against it)
  2. Restore a known-good backup of config.toml or delete it and let the app regenerate defaults (re-enter credentials afterwards)
  3. Check for schema changes after upgrading Codewhale and migrate/remove obsolete keys

Example fix

# before (config.toml)
model = "gpt-5"
api_provider = 123  # wrong type
# after
model = "gpt-5"
api_provider = "openai"
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: ensure the config parses before running logout flows
let cfg: Config = toml::from_str(&std::fs::read_to_string(&path)?)?;

Try / catch

match logout_provider(provider) {
    Err(e) if e.to_string().contains("Failed to parse config from") => {
        eprintln!("config.toml is corrupt; fix or restore it (path in message)");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Logging out a provider when the on-disk config.toml no longer deserializes into Config — e.g. invalid TOML syntax, unknown/renamed fields, wrong types after a version upgrade, or manual edits.

Common situations: Hand-edited config with a typo; config written by an older/newer Codewhale version with different schema; truncated file from a crashed write; stray keys added by another tool.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


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

Appendix: source

Thrown at crates/tui/src/config.rs:13397

        Some(slot) => crate::credentials::store::with_provider_write_lock(slot, || {
            clear_active_provider_api_key_under_lock(provider)
        }),
        None => clear_active_provider_api_key_under_lock(provider),
    }
}

fn clear_active_provider_api_key_under_lock(provider: &str) -> Result<()> {
    let config_path = credential_config_path()
        .context("Failed to resolve config path while clearing API keys.")?;

    if config_path.exists() {
        // `custom` is both the legacy root-shaped route id and a valid exact
        // `[providers.custom]` table key. Inspect the persisted shape before the
        // mutation so logout clears exactly one credential scope.
        let persisted = fs::read_to_string(&config_path)
            .with_context(|| format!("Failed to read config from {}", config_path.display()))?;
        let persisted_config: Config = toml::from_str(&persisted).map_err(|_| {
            anyhow::anyhow!(
                "Failed to parse config from {}; file contents were omitted",
                codewhale_config::quote_os_path(&config_path)
            )
        })?;
        let exact_literal_custom_table = provider == ApiProvider::Custom.as_str()
            && persisted_config
                .providers
                .as_ref()
                .and_then(|providers| providers.custom_provider_config(provider))
                .is_some();

        crate::config_persistence::mutate_config_document(&config_path, |doc| {
            // The root-level api_key is shared by the legacy DeepSeek and released
            // literal-custom config shapes. Exact named custom ids remain scoped
            // to their own table.
            if matches!(
                provider,
                value if value == ApiProvider::Deepseek.as_str()

View on GitHub (pinned to 73e0f67d83)