Hmbown/CodeWhale · error · anyhow::Error

could not inspect workspace .env link count: {error}

Error message

could not inspect workspace .env link count: {error}

What it means

On Windows, Codewhale detects hard-linked .env files by calling GetFileInformationByHandle on the already-open handle and reading nNumberOfLinks. If the Win32 call fails, the load stops with 'could not inspect workspace .env link count' — the security check is never skipped silently.

Source

Thrown at crates/tui/src/lib.rs:2648

#[cfg(windows)]
fn workspace_dotenv_has_multiple_links(
    file: &std::fs::File,
    _metadata: &std::fs::Metadata,
) -> Result<bool> {
    use std::os::windows::io::AsRawHandle;
    use windows::Win32::Foundation::HANDLE;
    use windows::Win32::Storage::FileSystem::{
        BY_HANDLE_FILE_INFORMATION, GetFileInformationByHandle,
    };

    let mut information = BY_HANDLE_FILE_INFORMATION::default();
    // SAFETY: `file` owns a live kernel handle for the already-open `.env`;
    // `information` remains writable for the duration of this synchronous
    // call. No path lookup or re-open occurs here.
    unsafe {
        GetFileInformationByHandle(HANDLE(file.as_raw_handle()), &mut information)
            .map_err(|error| anyhow!("could not inspect workspace .env link count: {error}"))?;
    }
    Ok(information.nNumberOfLinks > 1)
}

#[cfg(not(any(unix, windows)))]
fn workspace_dotenv_has_multiple_links(
    _file: &std::fs::File,
    _metadata: &std::fs::Metadata,
) -> Result<bool> {
    Ok(false)
}

#[cfg(unix)]
fn open_workspace_dotenv_without_following_links(path: &Path) -> Result<std::fs::File> {
    use std::os::unix::fs::OpenOptionsExt;

    std::fs::OpenOptions::new()
        .read(true)

View on GitHub (pinned to 8880682c63)

Solutions

  1. Move the workspace .env onto a local NTFS volume and retry
  2. Pause sync/antivirus agents that virtualize the workspace folder and retry
  3. Reconnect the network share, then retry
  4. Verify the file is a plain local file: fsutil hardlink list .env
Defensive patterns

Strategy: try-catch

Validate before calling

# PowerShell pre-flight: the file must be a local plain file
fsutil hardlink list .env   # must report exactly one link
(Get-Item .env).LinkType    # must be empty (not a symlink/junction)

Prevention

When it happens

Trigger: GetFileInformationByHandle fails: the handle was invalidated, the volume does not support the metadata query, a network redirector returned an error (SMB share dropping, DFS issues), or a filter driver blocked the query.

Common situations: A .env on a network share or in a OneDrive placeholder state; the file locked or converted by another process between open and query; antivirus or DLP filter drivers interfering with handle queries.

Related errors


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