kovidgoyal/kitty · error
Failed to stat %s with error: %w
Error message
Failed to stat %s with error: %w
What it means
After successfully opening the file, unix.Fstat on its descriptor failed. This is rare because the fd is already open — it usually indicates the filesystem can't stat the open inode (broken NFS/FUSE mount, fd closed underneath) or an fd inheritance edge case rather than a bad path.
Source
Thrown at tools/cmd/edit_in_kitty/main.go:188
if kill_if_signaled {
lp.KillIfSignalled()
return
}
return 1, &tui.KilledBySignal{Msg: fmt.Sprint("Killed by signal: ", ds), SignalName: ds}
}
return
}
func edit_in_kitty(path string, opts *Options) (exit_code int, err error) {
read_file, err := os.Open(path)
if err != nil {
return 1, fmt.Errorf("Failed to open %s for reading with error: %w", path, err)
}
defer read_file.Close()
var s unix.Stat_t
err = unix.Fstat(int(read_file.Fd()), &s)
if err != nil {
return 1, fmt.Errorf("Failed to stat %s with error: %w", path, err)
}
if s.Size > int64(opts.MaxFileSize)*1024*1024 {
return 1, fmt.Errorf("File size %s is too large for performant editing", humanize.Bytes(uint64(s.Size)))
}
file_data, err := io.ReadAll(read_file)
if err != nil {
return 1, fmt.Errorf("Failed to read from %s with error: %w", path, err)
}
read_file.Close()
data := strings.Builder{}
data.Grow(len(file_data) * 4)
add := func(key, val string) {
if data.Len() > 0 {
data.WriteString(",")
}
data.WriteString(key)View on GitHub (pinned to 6d5d0c4406)
Solutions
- Retry after remounting/reconnecting the network or FUSE filesystem
- Check mount health: mount | grep <fs>, df <path>
- If it reproduces on a specific file, stat it manually: stat <path> to see the kernel error
- Avoid editing files on flaky network mounts; copy locally first
Example fix
# before edit-in-kitty /mnt/nfs-shared/big.txt # ESTALE # after cp /mnt/nfs-shared/big.txt /tmp/ && edit-in-kitty /tmp/big.txt
Defensive patterns
Strategy: try-catch
Validate before calling
// Check mount health before editing files on network filesystems
if out, err := exec.Command("findmnt", "-n", "-o", "TARGET", path).Output(); err != nil {
return fmt.Errorf("path %s has no healthy mount", path)
} Try / catch
if err != nil && strings.Contains(err.Error(), "Failed to stat") {
// open succeeded but inode gone: retry once, then copy file locally
} Prevention
- Prefer local copies of files on NFS/FUSE before editing
- Detect ESTALE/EIO in wrapped errors and surface a remount hint
When it happens
Trigger: Calling edit_in_kitty on a file whose backing filesystem goes away between open and fstat (network filesystem disconnect, FUSE daemon crash), or on a pseudo-file where fstat returns an error despite open succeeding.
Common situations: Editing files on stale NFS mounts, sshfs/FUSE mounts that dropped, or special files under /proc or /sys with odd stat semantics.
Related errors
- Failed to open %s for reading with error: %w
- Failed to read from %s with error: %w
- %s is not readable and writeable
- Failed to get the current working directory with error: %w
- resolving base symlinks: %w
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/e78fc4b43937abb7.
Report an issue: GitHub.