From 793a4af6a0dd3ad08f9356011bf03d7e7b02c254 Mon Sep 17 00:00:00 2001 From: RejectModders <142326052+RejectModders@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:53:27 -0600 Subject: [PATCH 1/2] fix(reports): leave the server's folders out of error reports Reports in the log channel showed the end of each file's path and the frame, whose text holds the full path on the server. --- CHANGELOG.md | 5 +++++ core/ui/reports.py | 33 ++++++++++++++++++++++++++++----- tests/test_error_handler.py | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6855cc9..46715f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ The format follows [Keep a Changelog](https://keepachangelog.com/). - A lost database connection is retried on the same pool. Before, each failure opened another pool of ten connections. +### Security + +- Error reports in the log channel no longer show where the bot's files are + on the server. + ## 1.0.2 - 2026-11-29 ### Changed diff --git a/core/ui/reports.py b/core/ui/reports.py index 564838a..25ae2a5 100644 --- a/core/ui/reports.py +++ b/core/ui/reports.py @@ -17,6 +17,7 @@ _FENCE = "```" # The innermost calls, where the error happened. _CALLS = 8 +_ROOT = Path(__file__).resolve().parents[2] def print_error(heading: str, error: BaseException) -> None: @@ -34,6 +35,29 @@ def print_error(heading: str, error: BaseException) -> None: traceback.print_exception(error, file=sys.stderr) +def place(filename: str) -> str: + """ + Name a source file without the folders of the server. + + Parameters + ---------- + filename : str + The path of the file. + + Returns + ------- + str + The path inside a library or the bot, otherwise its last two parts. + """ + path = Path(filename) + parts = path.parts + if "site-packages" in parts: + return "/".join(parts[parts.index("site-packages") + 1 :]) + if path.is_relative_to(_ROOT): + return path.relative_to(_ROOT).as_posix() + return "/".join(parts[-2:]) + + def _cause(error: BaseException) -> str: """ Name an error and the calls that led to it, without its message. @@ -44,9 +68,10 @@ def _cause(error: BaseException) -> str: if isinstance(error, app_commands.CommandInvokeError): error = error.original lines = [f"{type(error).__qualname__} (the message is in the console)"] - for call in traceback.extract_tb(error.__traceback__)[-_CALLS:]: - where = "/".join(Path(call.filename).parts[-3:]) - lines.append(f"{where}:{call.lineno} in {call.name}") + lines.extend( + f"{place(call.filename)}:{call.lineno} in {call.name}" + for call in traceback.extract_tb(error.__traceback__)[-_CALLS:] + ) return "\n".join(lines) @@ -77,12 +102,10 @@ async def send_report( if not isinstance(channel, discord.abc.Messageable): _logger.warning("LOG_CHANNEL takes no messages: %s", title) return - trace = error.__traceback__ text = ( f"{context}\nError caused by-\nAuthor Name: {interaction.user}" f"\nAuthor ID: {interaction.user.id}\n" f"\nError Type-\n{type(error)}\n" - f"\nError Type Description-\n{trace.tb_frame if trace else None}\n" f"\nCause-\n{_cause(error)}" ) title = title[:_TITLE_LIMIT] diff --git a/tests/test_error_handler.py b/tests/test_error_handler.py index b5c6021..c59ece7 100644 --- a/tests/test_error_handler.py +++ b/tests/test_error_handler.py @@ -1,6 +1,7 @@ """What users and the log channel are told when a command fails.""" import logging +from pathlib import Path from unittest.mock import MagicMock import discord @@ -10,8 +11,10 @@ from core import Bot from core.config import LOG_CHANNEL from core.extensions.error_handler import ErrorHandler +from core.ui import reports from tests.ui_helpers import PRESSER, interaction, report, shown +ROOT = Path(__file__).resolve().parent.parent TOKEN = "MTAx.not-a-real-token" # noqa: S105 (not a real token) PRIVATE = f"password=hunter2 {TOKEN} the user wrote: my address is here" APOLOGY = ( @@ -129,7 +132,6 @@ async def test_the_report_says_who_what_and_where() -> None: "Author Name: someone", f"Author ID: {PRESSER}", "", - "Error Type Description-\n None: + command = _command("modmail", "close") + item = interaction() + item.command = command + + await _handler().on_error(item, _invoke_error(command)) + + text = report(item) + for folder in (str(ROOT), ROOT.as_posix(), ROOT.parent.name, " None: + assert reports.place(filename) == shown + + async def test_a_long_traceback_still_fits() -> None: def deeper(left: int) -> None: if left: From d7cb70a64443b97194103126f8dd09cdb1afaa48 Mon Sep 17 00:00:00 2001 From: RejectModders <142326052+RejectModders@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:09:26 -0600 Subject: [PATCH 2/2] docs(changelog): say which error reports hide the server's folders The report the launcher posts after a rolled back update still carries the paths from the bot's error output. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46715f9..02ad197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,8 +22,8 @@ The format follows [Keep a Changelog](https://keepachangelog.com/). ### Security -- Error reports in the log channel no longer show where the bot's files are - on the server. +- Reports about a failed command, button or form no longer show where the + bot's files are on the server. ## 1.0.2 - 2026-11-29