fix: normalize fetch_guild errors; guard embed Log field value (v0.1.2)
- _get_guild catches discord.HTTPException (NotFound/Forbidden/HTTPException) from fetch_guild and re-raises the lib's ValueError; the old 'if not resolved' branch was unreachable since fetch_guild never returns None (L10) - build_embed substitutes '(no message)' for empty details and truncates to 1024, so a logging call never 400s the embed send on an empty/over-long message (L11). Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
parent
e20c7bbda3
commit
3a580e8239
@ -10,13 +10,13 @@ live from `bot.settings` so it can change at runtime via a command.
|
||||
`requirements.txt`:
|
||||
|
||||
```
|
||||
dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.1
|
||||
dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.2
|
||||
```
|
||||
|
||||
Direct:
|
||||
|
||||
```bash
|
||||
pip install "dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.1"
|
||||
pip install "dpy_logger @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_logger.git@v0.1.2"
|
||||
```
|
||||
|
||||
Requires `discord.py` (pulled transitively).
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "dpy_logger"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
description = "Leveled Discord channel logger for discord.py — config-free, injectable, installable."
|
||||
requires-python = ">=3.10"
|
||||
dependencies = [
|
||||
|
||||
@ -116,10 +116,16 @@ class DPYLogger:
|
||||
"""resolve a guild from id-or-object, raising if unresolvable"""
|
||||
if guild:
|
||||
if isinstance(guild, int):
|
||||
resolved = self.bot.get_guild(guild) or await self.bot.fetch_guild(guild)
|
||||
if not resolved:
|
||||
raise ValueError(f"[dpy_logger] failed to fetch guild {guild}")
|
||||
resolved = self.bot.get_guild(guild)
|
||||
if resolved is not None:
|
||||
return resolved
|
||||
# fetch_guild never returns None — it raises NotFound/Forbidden/
|
||||
# HTTPException; normalize those to the lib's ValueError so callers see
|
||||
# one error type at setup
|
||||
try:
|
||||
return await self.bot.fetch_guild(guild)
|
||||
except discord.HTTPException as error:
|
||||
raise ValueError(f"[dpy_logger] failed to fetch guild {guild}: {error}") from error
|
||||
if isinstance(guild, discord.Guild):
|
||||
return guild
|
||||
raise ValueError("[dpy_logger] no guild available for logging")
|
||||
@ -159,7 +165,13 @@ class DPYLogger:
|
||||
em.add_field(name="Action", value=f"`{action}`", inline=True)
|
||||
if actor:
|
||||
em.add_field(name="Actor", value=f"`{actor}`", inline=True)
|
||||
em.add_field(name="Log", value=details, inline=False)
|
||||
# discord rejects an empty field value (50035) and truncates nothing itself, so
|
||||
# an empty or >1024-char message would 400 the send; substitute + cap to keep
|
||||
# every logging call producing a valid embed
|
||||
log_value = str(details) if details else "(no message)"
|
||||
if len(log_value) > 1024:
|
||||
log_value = log_value[:1021] + "..."
|
||||
em.add_field(name="Log", value=log_value, inline=False)
|
||||
em.timestamp = datetime.now(self.timezone)
|
||||
em.set_footer(text=f"{self.footer} Logging".strip(), icon_url=self.avatar)
|
||||
return em
|
||||
|
||||
Loading…
Reference in New Issue
Block a user