kovidgoyal/kitty · error
Failed while reading from file: %s with error: %s
Error message
Failed while reading from file: %s with error: %s
What it means
fread set the stream error flag with an errno other than EINTR while reading the PNG file, so the read loop aborts, frees the buffer, and returns false. The strerror(errno) text (e.g. I/O error, EIO) identifies the underlying filesystem/device problem.
Source
Thrown at kitty/graphics.c:553
fclose(fp);
return false;
}
while (!feof(fp)) {
if (capacity - pos < 1024) {
capacity *= 2;
unsigned char *new_buf = realloc(buf, capacity);
if (!new_buf) {
free(buf);
log_error("Out of memory reading PNG file at: %s", path_for_error_messages);
fclose(fp);
return false;
}
buf = new_buf;
}
pos += fread(buf + pos, sizeof(char), capacity - pos, fp);
int saved_errno = errno;
if (ferror(fp) && saved_errno != EINTR) {
log_error("Failed while reading from file: %s with error: %s", path_for_error_messages, strerror(saved_errno));
free(buf);
return false;
}
}
bool ret = png_from_data(buf, pos, path_for_error_messages, data, width, height, sz);
free(buf);
return ret;
}
bool
png_path_to_bitmap(const char *path, uint8_t **data, unsigned int *width, unsigned int *height, size_t *sz) {
FILE *fp = fopen(path, "r");
if (fp == NULL) {
log_error("The PNG image: %s could not be opened with error: %s", path, strerror(errno));
return false;
}
bool ret = png_from_file_pointer(fp, path, data, width, height, sz);
fclose(fp);View on GitHub (pinned to 6d5d0c4406)
Solutions
- Check dmesg/storage health for I/O errors; remount the affected filesystem
- Move the image to reliable local storage and update kitty.conf
- Verify the file reads fully: cmp it against a copy, or md5sum twice
- Re-save the PNG after confirming the source file is intact
Defensive patterns
Strategy: retry
Validate before calling
import os
def readable_intact(path: str) -> bool:
try:
st = os.stat(path)
if not os.path.isfile(path) or st.st_size < 8:
return False
with open(path, 'rb') as f:
return f.read(8) == b'\x89PNG\r\n\x1a\n'
except OSError:
return False Try / catch
// C: the code already skips EINTR; higher-level callers can retry the whole load once on transient EIO
if (!png_path_to_bitmap(p, ...)) { if (errno == EIO) retry_once(); } Prevention
- Store kitty assets on reliable local disk, not flaky network mounts
- Verify files with checksums after syncing configs
- Check dmesg early when EIO appears — it usually precedes disk failure
When it happens
Trigger: Reading a PNG from a failing disk (EIO), an unplugged USB/network mount (EIO/ENODEV), a truncated NFS/FUSE file, or a file on a mount that disappears mid-read; EINTR reads are retried implicitly by being skipped from the error branch.
Common situations: background_image stored on a network share that drops; SD-card corruption on Raspberry Pi; VM shared-folder (vboxsf/prl_fs) I/O glitches; file deleted or truncated while kitty was starting.
Related errors
- failed to read cached image metadata: %w
- failed to read cached image frame %d data: %w
- failed to read the directory %s with error: %w
- Failed to rename temporary file used for downloading to dest
- Could not find any writable data directories. Make sure XDG_
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/0e0ad951cbf2207b.
Report an issue: GitHub.