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 <dev@disqualifier.me>
This commit is contained in:
2026-07-06 00:18:14 -04:00
parent 7a1ab625fa
commit d611797882
+6
View File
@@ -255,12 +255,18 @@ class DPYCache:
seeks to the original position and copies the bytes for a caller-supplied stream; 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""" raises DPYCacheError if the underlying stream can't be safely re-read"""
if source._owner and hasattr(source.fp, "name"): if source._owner and hasattr(source.fp, "name"):
try:
return discord.File( return discord.File(
source.fp.name, source.fp.name,
filename=name, filename=name,
spoiler=source.spoiler, spoiler=source.spoiler,
description=source.description, 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: if source.fp.closed:
raise DPYCacheError( raise DPYCacheError(
f"discord.File source for {name!r} is already closed and can't be safely " f"discord.File source for {name!r} is already closed and can't be safely "