zed-industries/zed · error · anyhow::Error
Could find a path for the file handle
Error message
Could find a path for the file handle
What it means
On macOS, after fcntl(F_GETPATH) succeeded, converting the returned C string into an OsStr/path failed — the guard 'Could find a path for the file handle' fires in the post-syscall conversion step when no valid path bytes could be extracted for the handle. The syscall worked but the buffer-to-path step yielded nothing usable.
Source
Thrown at crates/fs/src/fs.rs:482
}
impl FileHandle for std::fs::File {
#[cfg(target_os = "macos")]
fn current_path(&self, _: &Arc<dyn Fs>) -> Result<PathBuf> {
use std::{
ffi::{CStr, OsStr},
os::unix::ffi::OsStrExt,
};
let fd = self.as_fd();
let mut path_buf = MaybeUninit::<[u8; libc::PATH_MAX as usize]>::uninit();
let result = unsafe { libc::fcntl(fd.as_raw_fd(), libc::F_GETPATH, path_buf.as_mut_ptr()) };
anyhow::ensure!(result != -1, "fcntl returned -1");
// SAFETY: `fcntl` will initialize the path buffer.
let c_str = unsafe { CStr::from_ptr(path_buf.as_ptr().cast()) };
anyhow::ensure!(!c_str.is_empty(), "Could find a path for the file handle");
let path = PathBuf::from(OsStr::from_bytes(c_str.to_bytes()));
Ok(path)
}
#[cfg(target_os = "linux")]
fn current_path(&self, _: &Arc<dyn Fs>) -> Result<PathBuf> {
let fd = self.as_fd();
let fd_path = format!("/proc/self/fd/{}", fd.as_raw_fd());
let new_path = std::fs::read_link(fd_path)?;
if new_path
.file_name()
.is_some_and(|f| f.to_string_lossy().ends_with(" (deleted)"))
{
anyhow::bail!("file was deleted")
};
Ok(new_path)
}View on GitHub (pinned to 9d272b0363)
Solutions
- Handle the failure by treating the file as having no recoverable path (untitled/anonymous buffer)
- Track the open path at creation time as a durable fallback instead of querying the fd
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/fs/src/fs.rs:446 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/8f29436c36e10123.
Report an issue: GitHub.