diff --git a/src/dpy_cache/dpy_cache.py b/src/dpy_cache/dpy_cache.py index 4ec767d..abe5858 100644 --- a/src/dpy_cache/dpy_cache.py +++ b/src/dpy_cache/dpy_cache.py @@ -255,12 +255,18 @@ class DPYCache: seeks to the original position and copies the bytes for a caller-supplied stream; raises DPYCacheError if the underlying stream can't be safely re-read""" if source._owner and hasattr(source.fp, "name"): - return discord.File( - source.fp.name, - filename=name, - spoiler=source.spoiler, - description=source.description, - ) + try: + return discord.File( + source.fp.name, + filename=name, + spoiler=source.spoiler, + description=source.description, + ) + except OSError as err: + raise DPYCacheError( + f"discord.File source for {name!r} could not be reopened from " + f"{source.fp.name!r} (backing file missing or unreadable)" + ) from err if source.fp.closed: raise DPYCacheError( f"discord.File source for {name!r} is already closed and can't be safely "