Hmbown/CodeWhale · error

Codewhale-owned xAI OAuth path has the wrong filesystem type

Error message

Codewhale-owned xAI OAuth path has the wrong filesystem type

What it means

validate_windows_handle_path also verifies the opened object has the expected filesystem type: a directory when expect_directory is true, a regular file otherwise. If the handle resolves to the wrong kind of object (e.g. a file where the credentials directory should be, or a directory at the token-file name), the layout contract is broken and the error is raised.

Solutions

  1. Check the path with `dir` / `Get-Item` and fix the type: delete the wrongly typed entry and recreate the directory (or re-login to recreate the file)
  2. Recreate the credentials directory: `mkdir %USERPROFILE%\.codewhale\xai` then log in again
  3. Correct the path in config so it points at the directory, not a file

Example fix

// before (auth.json is a directory)
rmdir C:\Users\me\.codewhale\xai\auth.json
// after: re-login to recreate the token file
Defensive patterns

Strategy: validation

Validate before calling

fn path_type(p: &std::path::Path) -> Result<&'static str, std::io::Error> {
    let m = std::fs::metadata(p)?;
    Ok(if m.is_dir() { "dir" } else if m.is_file() { "file" } else { "other" })
}

Try / catch

let store = match XaiCredentialStore::open(&dir) {
    Err(e) if e.to_string().contains("wrong filesystem type") => {
        std::fs::remove_file(&dir).ok();
        std::fs::create_dir_all(&dir)?;
        XaiCredentialStore::open(&dir)?
    }
    r => r?,
};

Prevention

When it happens

Trigger: The credentials directory path points at a regular file, or the token-file name inside it is a directory; opening the store when ~/.codewhale/xai was accidentally replaced by a file (or vice versa) by a script or manual mv.

Common situations: A cleanup script doing `rm -rf` partially or creating a file named like the directory; extracting an archive over the profile that turned the directory into a file; manually creating a folder named `auth.json`.

Related errors


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

Appendix: source

Thrown at crates/config/src/xai_credentials.rs:1349

    use std::os::windows::ffi::OsStringExt as _;
    use std::os::windows::fs::MetadataExt as _;
    use std::os::windows::io::AsRawHandle as _;
    use windows_sys::Win32::Storage::FileSystem::{
        FILE_ATTRIBUTE_REPARSE_POINT, FILE_NAME_NORMALIZED, GetFinalPathNameByHandleW,
        VOLUME_NAME_DOS,
    };

    let metadata = file.metadata().with_context(|| {
        format!(
            "inspecting Codewhale-owned path {}",
            crate::quote_os_path(expected)
        )
    })?;
    anyhow::ensure!(
        metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT == 0,
        "Codewhale-owned xAI OAuth path must not be a reparse point"
    );
    anyhow::ensure!(
        if expect_directory {
            metadata.is_dir()
        } else {
            metadata.is_file()
        },
        "Codewhale-owned xAI OAuth path has the wrong filesystem type"
    );
    let flags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS;
    let handle = file.as_raw_handle();
    // SAFETY: null output asks only for the required UTF-16 length.
    let needed = unsafe { GetFinalPathNameByHandleW(handle, std::ptr::null_mut(), 0, flags) };
    if needed == 0 {
        return Err(std::io::Error::last_os_error())
            .context("resolving Codewhale-owned xAI OAuth handle path");
    }
    let mut buffer = vec![0u16; needed as usize + 1];
    // SAFETY: the buffer is writable and the handle remains valid.
    let written = unsafe {

View on GitHub (pinned to 73e0f67d83)