{"record":{"id":"fec0735a0e2e5850","repo":"zed-industries/zed","slug":"getfinalpathnamebyhandlew-failed-to-write-path","errorCode":null,"errorMessage":"GetFinalPathNameByHandleW failed to write path","messagePattern":"GetFinalPathNameByHandleW failed to write path","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs.rs","lineNumber":547,"sourceCode":"        use windows::Win32::Foundation::HANDLE;\n        use windows::Win32::Storage::FileSystem::{\n            FILE_NAME_NORMALIZED, GetFinalPathNameByHandleW,\n        };\n\n        let handle = HANDLE(self.as_raw_handle() as _);\n\n        // Query required buffer size (in wide chars)\n        let required_len =\n            unsafe { GetFinalPathNameByHandleW(handle, &mut [], FILE_NAME_NORMALIZED) };\n        anyhow::ensure!(\n            required_len != 0,\n            \"GetFinalPathNameByHandleW returned 0 length\"\n        );\n\n        // Allocate buffer and retrieve the path\n        let mut buf: Vec<u16> = vec![0u16; required_len as usize + 1];\n        let written = unsafe { GetFinalPathNameByHandleW(handle, &mut buf, FILE_NAME_NORMALIZED) };\n        anyhow::ensure!(\n            written != 0,\n            \"GetFinalPathNameByHandleW failed to write path\"\n        );\n\n        let os_str: OsString = OsString::from_wide(&buf[..written as usize]);\n        anyhow::ensure!(!os_str.is_empty(), \"Could find a path for the file handle\");\n        Ok(PathBuf::from(os_str))\n    }\n}\n\npub struct RealWatcher {}\n\nimpl RealFs {\n    pub fn new(git_binary_path: Option<PathBuf>, executor: BackgroundExecutor) -> Arc<Self> {\n        Arc::new_cyclic(|this| Self {\n            this: this.clone(),\n            bundled_git_binary_path: git_binary_path,\n            native_watcher: fs_watcher::OsWatcher::new(","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/fs/src/fs.rs#L529-L565","documentation":"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.","triggerScenarios":"Thrown at crates/fs/src/fs.rs:511 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-query the required length and retry once with a fresh buffer","Fall back to the open-time path if the final path remains unobtainable"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}