Hmbown/CodeWhale · error · anyhow::Error

xAI/Grok credential file {} is not valid credential JSON

Error message

xAI/Grok credential file {} is not valid credential JSON

What it means

JSON parse guard in parse_auth_file: the raw contents of the xAI/Grok credential file at the given path could not be deserialized as JSON. The file is either corrupted, truncated, or was overwritten with non-JSON content.

Source

Thrown at crates/tui/src/xai_oauth.rs:824

    };
    parse_auth_file(&raw, &store.path_for(name)?).map(Some)
}

fn load_external_auth_file(
    grant: &codewhale_config::ExternalCredentialReadGrant,
) -> Result<AuthFile> {
    let Some(raw) = crate::external_credentials::read_to_string(grant)? else {
        bail!(
            "external xAI/Grok credential file not found at {}",
            codewhale_config::quote_os_path(grant.path())
        );
    };
    parse_auth_file(&raw, grant.path())
}

fn parse_auth_file(raw: &str, path: &Path) -> Result<AuthFile> {
    let value: Value = serde_json::from_str(raw).map_err(|_| {
        anyhow::anyhow!(
            "xAI/Grok credential file {} is not valid credential JSON",
            codewhale_config::quote_os_path(path)
        )
    })?;
    let obj = value.as_object().ok_or_else(|| {
        anyhow::anyhow!(
            "xAI/Grok credential file {} must be a JSON object of entries",
            codewhale_config::quote_os_path(path)
        )
    })?;
    let mut out = BTreeMap::new();
    for (k, v) in obj {
        match serde_json::from_value::<GrokAuthEntry>(v.clone()) {
            Ok(entry) => {
                out.insert(k.clone(), entry);
            }
            Err(_) => {
                tracing::warn!(

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Re-authenticate to regenerate the credential file: `grok login` for external files, or `codewhale auth xai-device` for Codewhale-owned files.
  2. Inspect the file at the quoted path to check for corruption or accidental overwriting.
  3. Restore the credential file from a backup if one exists.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/xai_oauth.rs:824 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/3d710f1130a77a53. Report an issue: GitHub.