From d611797882cc4b21ed625a3dbc589849270c8db0 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 6 Jul 2026 00:18:14 -0400 Subject: [PATCH] fix: wrap owner-reopen File rebuild in DPYCacheError (dpycache-1) _fresh_file_from_source wrapped the stream-copy branch's failures in DPYCacheError but called discord.File(source.fp.name, ...) in the owner-reopen branch with no try - a path-backed File whose backing file was deleted between caching calls raised a raw FileNotFoundError/PermissionError where the module's fail-loud contract promises DPYCacheError for every lib-domain fault. Wrap the reopen the same way the stream-copy branch already is. Signed-off-by: disqualifier --- src/dpy_cache/dpy_cache.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 "