fix: self-heal retry rebuilds consumed File objects (no 0-byte re-upload)
send() and send_any() retry with the exact same discord.File objects after healing a dead webhook, but discord.py closes every File on the first send's exit - a buffer-backed File's retry then uploads 0 bytes silently (the buffer sits at EOF and nothing calls reset()), and a path-backed File raises "I/O operation on closed file" instead. The healed retry in both methods now routes kwargs through _rebuild_files_in_kwargs(), which rebuilds a fresh discord.File per entry in file=/files= from its original source (reopens a path-backed File, rewinds a still-seekable buffer) before the retry send. A File that can't be safely rebuilt raises ValueError rather than silently sending an empty attachment. The first, non-retry send is untouched. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -8,7 +8,7 @@ each time (wasteful, rate-limited, and it leaks toward the cap).
|
||||
## Install
|
||||
|
||||
```
|
||||
dpy_webhooks @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_webhooks.git@v0.1.1
|
||||
dpy_webhooks @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_webhooks.git@v0.1.2
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -83,7 +83,12 @@ The module docstring (`help(dpy_webhooks)` / IDE hover) is the source of truth.
|
||||
|
||||
**Self-heal.** If `send` hits a dead webhook (deleted server-side / invalid token), the lib
|
||||
clears the record, recreates the webhook, and retries the send **once**; a second failure
|
||||
raises loud.
|
||||
raises loud. If the retried send carries `file=`/`files=`, the lib rebuilds a fresh
|
||||
`discord.File` for each one before retrying — discord.py closes every File's handle after
|
||||
the first send, so resending the same object would upload 0 bytes (or raise, for a
|
||||
path-backed File). A File that can't be safely rebuilt (a non-seekable, already-exhausted
|
||||
in-memory buffer with no backing path) raises `ValueError` rather than silently sending an
|
||||
empty attachment.
|
||||
|
||||
**Fail-loud.** Nothing is swallowed to `None`. A channel already at 10 webhooks raises
|
||||
`WebhookCapacityError` (pass `evict_oldest=True` to reclaim the oldest instead). Missing
|
||||
|
||||
Reference in New Issue
Block a user