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:
@@ -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"):
|
||||||
return discord.File(
|
try:
|
||||||
source.fp.name,
|
return discord.File(
|
||||||
filename=name,
|
source.fp.name,
|
||||||
spoiler=source.spoiler,
|
filename=name,
|
||||||
description=source.description,
|
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:
|
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 "
|
||||||
|
|||||||
Reference in New Issue
Block a user