zed-industries/zed · error · anyhow::Error

GetFinalPathNameByHandleW failed to write path

Error message

GetFinalPathNameByHandleW failed to write path

What it means

On Windows, the second GetFinalPathNameByHandleW call — which should write the final path into the allocated buffer — did not succeed/return the expected length. The size query worked, but writing failed, indicating the handle or path state changed between the two calls or the buffer length was wrong; the guard rejects continuing with a partially written buffer.

Source

Thrown at crates/fs/src/fs.rs:547

        use windows::Win32::Foundation::HANDLE;
        use windows::Win32::Storage::FileSystem::{
            FILE_NAME_NORMALIZED, GetFinalPathNameByHandleW,
        };

        let handle = HANDLE(self.as_raw_handle() as _);

        // Query required buffer size (in wide chars)
        let required_len =
            unsafe { GetFinalPathNameByHandleW(handle, &mut [], FILE_NAME_NORMALIZED) };
        anyhow::ensure!(
            required_len != 0,
            "GetFinalPathNameByHandleW returned 0 length"
        );

        // Allocate buffer and retrieve the path
        let mut buf: Vec<u16> = vec![0u16; required_len as usize + 1];
        let written = unsafe { GetFinalPathNameByHandleW(handle, &mut buf, FILE_NAME_NORMALIZED) };
        anyhow::ensure!(
            written != 0,
            "GetFinalPathNameByHandleW failed to write path"
        );

        let os_str: OsString = OsString::from_wide(&buf[..written as usize]);
        anyhow::ensure!(!os_str.is_empty(), "Could find a path for the file handle");
        Ok(PathBuf::from(os_str))
    }
}

pub struct RealWatcher {}

impl RealFs {
    pub fn new(git_binary_path: Option<PathBuf>, executor: BackgroundExecutor) -> Arc<Self> {
        Arc::new_cyclic(|this| Self {
            this: this.clone(),
            bundled_git_binary_path: git_binary_path,
            native_watcher: fs_watcher::OsWatcher::new(

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Re-query the required length and retry once with a fresh buffer
  2. Fall back to the open-time path if the final path remains unobtainable
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/fs/src/fs.rs:511 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/fec0735a0e2e5850. Report an issue: GitHub.