{"record":{"id":"fa97cb42a0ad66ab","repo":"zed-industries/zed","slug":"getfinalpathnamebyhandlew-returned-0-length","errorCode":null,"errorMessage":"GetFinalPathNameByHandleW returned 0 length","messagePattern":"GetFinalPathNameByHandleW returned 0 length","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs.rs","lineNumber":539,"sourceCode":"    }\n\n    #[cfg(target_os = \"windows\")]\n    fn current_path(&self, _: &Arc<dyn Fs>) -> Result<PathBuf> {\n        use std::ffi::OsString;\n        use std::os::windows::ffi::OsStringExt;\n        use std::os::windows::io::AsRawHandle;\n\n        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","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/fs/src/fs.rs#L521-L557","documentation":"On Windows, the first GetFinalPathNameByHandleW call — used to query the buffer size needed for the final path — returned 0. A zero length means the API failed (the return is the required length on success), typically because the handle is not a file handle, the file was deleted, or access rights are insufficient; GetLastError holds the reason.","triggerScenarios":"Thrown at crates/fs/src/fs.rs:503 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect GetLastError to identify the cause (ERROR_INVALID_HANDLE, ERROR_ACCESS_DENIED, path deleted)","Fall back to the path captured when the file was opened, as the final path cannot be queried for this handle"],"exampleFix":null,"handlingStrategy":"fallback","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"}