{"record":{"id":"6523854fc0792614","repo":"zed-industries/zed","slug":"fcntl-returned-1","errorCode":null,"errorMessage":"fcntl returned -1","messagePattern":"fcntl returned -1","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs.rs","lineNumber":478,"sourceCode":"}\n\npub trait FileHandle: Send + Sync + std::fmt::Debug {\n    fn current_path(&self, fs: &Arc<dyn Fs>) -> Result<PathBuf>;\n}\n\nimpl FileHandle for std::fs::File {\n    #[cfg(target_os = \"macos\")]\n    fn current_path(&self, _: &Arc<dyn Fs>) -> Result<PathBuf> {\n        use std::{\n            ffi::{CStr, OsStr},\n            os::unix::ffi::OsStrExt,\n        };\n\n        let fd = self.as_fd();\n        let mut path_buf = MaybeUninit::<[u8; libc::PATH_MAX as usize]>::uninit();\n\n        let result = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_GETPATH, path_buf.as_mut_ptr()) };\n        anyhow::ensure!(result != -1, \"fcntl returned -1\");\n\n        // SAFETY: `fcntl` will initialize the path buffer.\n        let c_str = unsafe { CStr::from_ptr(path_buf.as_ptr().cast()) };\n        anyhow::ensure!(!c_str.is_empty(), \"Could find a path for the file handle\");\n        let path = PathBuf::from(OsStr::from_bytes(c_str.to_bytes()));\n        Ok(path)\n    }\n\n    #[cfg(target_os = \"linux\")]\n    fn current_path(&self, _: &Arc<dyn Fs>) -> Result<PathBuf> {\n        let fd = self.as_fd();\n        let fd_path = format!(\"/proc/self/fd/{}\", fd.as_raw_fd());\n        let new_path = std::fs::read_link(fd_path)?;\n        if new_path\n            .file_name()\n            .is_some_and(|f| f.to_string_lossy().ends_with(\" (deleted)\"))\n        {\n            anyhow::bail!(\"file was deleted\")","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/fs/src/fs.rs#L460-L496","documentation":"On macOS, the libc fcntl(F_GETPATH) call used to recover a file's current path from its descriptor returned -1. The kernel could not produce a path for this fd — possible right after the file is unlinked, for certain virtual files, or on an invalid fd; errno holds the precise reason but is not captured in this message.","triggerScenarios":"Thrown at crates/fs/src/fs.rs:442 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check errno (via std::io::Error::last_os_error) to distinguish ENOENT (deleted file) from EBADF","Fall back to remembering the path at open time instead of recovering it from the fd","Treat unlinked files as unsaved/anonymous — no path recovery is possible for them"],"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-14T00:17:10.932Z"}