Skip to content

Commit

Permalink
Use a placeholder essage if an error doesn't have one
Browse files Browse the repository at this point in the history
It seems that sometimes the Context passed to an on_command_error does
not have the `message` attribute, despite the documentation. Falling
back to a placeholder message if that is the case
  • Loading branch information
Gehock committed Apr 2, 2024
1 parent 6a5fb32 commit 2dedfd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The project uses semantic versioning (see [SemVer](https://semver.org)).

## [Unreleased]

### Fixed

- Use a placeholder message if a command error doesn't include one. This
should fix some of the incorrect warnings about messages with >2000
characters when trying to edit old events.

## v0.45.0 - 2024-03-27

### Added
Expand Down
10 changes: 8 additions & 2 deletions src/operationbot/commandListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,13 @@ async def on_command_error(ctx: Context, error: Exception):
traceback.format_exception(type(error), error, error.__traceback__, 2)
)

lines = ctx.message.clean_content.split("\n")
if hasattr(ctx, "message"):
lines = ctx.message.clean_content.split("\n")
clean_content = ctx.message.clean_content
else:
lines = "No associated message"
clean_content = lines

logging.error(f"{lines=}")
if len(lines) > 1:
# Show only first line of the message
Expand All @@ -1190,7 +1196,7 @@ async def on_command_error(ctx: Context, error: Exception):
"Received error message that's over 2000 characters, check "
"the log for the full error."
)
logging.error("Message:", ctx.message.clean_content)
logging.error("Message:", clean_content)
msg = f"{msg[:1990]} [...]```"
await ctx.send(msg)

Expand Down

0 comments on commit 2dedfd6

Please sign in to comment.