{"record":{"id":"d0c4102222c2e28d","repo":"Hmbown/CodeWhale","slug":"could-not-inspect-workspace-env-link-count-erro","errorCode":null,"errorMessage":"could not inspect workspace .env link count: {error}","messagePattern":"could not inspect workspace \\.env link count: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":3000,"sourceCode":"\n#[cfg(windows)]\nfn workspace_dotenv_has_multiple_links(\n    file: &std::fs::File,\n    _metadata: &std::fs::Metadata,\n) -> Result<bool> {\n    use std::os::windows::io::AsRawHandle;\n    use windows::Win32::Foundation::HANDLE;\n    use windows::Win32::Storage::FileSystem::{\n        BY_HANDLE_FILE_INFORMATION, GetFileInformationByHandle,\n    };\n\n    let mut information = BY_HANDLE_FILE_INFORMATION::default();\n    // SAFETY: `file` owns a live kernel handle for the already-open `.env`;\n    // `information` remains writable for the duration of this synchronous\n    // call. No path lookup or re-open occurs here.\n    unsafe {\n        GetFileInformationByHandle(HANDLE(file.as_raw_handle()), &mut information)\n            .map_err(|error| anyhow!(\"could not inspect workspace .env link count: {error}\"))?;\n    }\n    Ok(information.nNumberOfLinks > 1)\n}\n\n#[cfg(not(any(unix, windows)))]\nfn workspace_dotenv_has_multiple_links(\n    _file: &std::fs::File,\n    _metadata: &std::fs::Metadata,\n) -> Result<bool> {\n    Ok(false)\n}\n\n#[cfg(unix)]\nfn open_workspace_dotenv_without_following_links(path: &Path) -> Result<std::fs::File> {\n    use std::os::unix::fs::OpenOptionsExt;\n\n    std::fs::OpenOptions::new()\n        .read(true)","sourceCodeStart":2982,"sourceCodeEnd":3018,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L2982-L3018","documentation":"On Windows, hard-link/symlink detection for the workspace `.env` uses `GetFileInformationByHandle` to read `nNumberOfLinks`. If the Win32 call fails, the error is wrapped with this message, because the loader must prove the file is unique before trusting its contents.","triggerScenarios":"The `GetFileInformationByHandle` syscall fails (invalid handle, AV interference, filesystem without link metadata) inside `workspace_dotenv_has_multiple_links` on Windows.","commonSituations":"The `.env` lives on an unusual filesystem (network drive, WSL mount) where the handle query fails, or security software blocks handle inspection.","solutions":["Move the workspace `.env` onto a local NTFS volume.","Check the `{error}` suffix (Win32 error code) for the failing subsystem (AV, permissions, filesystem).","Ensure the file is a normal regular file, not on a UNC/network share, then retry startup."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match load_workspace_dotenv_credentials_from_path(&path) {\n    Err(e) if e.to_string().contains(\"link count\") => {\n        eprintln!(\"move .env to local NTFS storage: {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["On Windows, keep `.env` on local NTFS, not UNC/network shares or WSL mounts.","Exclude the workspace from AV handle-inspection interference if it recurs.","Never hard-link or symlink the workspace `.env`."],"tags":["windows","filesystem","security","dotenv"],"backgroundTag":"file-read-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}