Skip to content

Suppress NotFound for batch deletion.#1846

Merged
jchristgit merged 1 commit into
mainfrom
suppress-notfound-messages-on-delete
Sep 24, 2021
Merged

Suppress NotFound for batch deletion.#1846
jchristgit merged 1 commit into
mainfrom
suppress-notfound-messages-on-delete

Conversation

@jchristgit
Copy link
Copy Markdown
Contributor

@jchristgit jchristgit commented Sep 24, 2021

Fixes BOT-1MF

I will copy my comment from the code, as it explains why we want this:

In the rare case where we found messages matching the spam filter across
multiple channels, it is possible that a single channel will only
contain a single message to delete. If that should be the case,
discord.py will use the "delete single message" endpoint instead of the
bulk delete endpoint, and the single message deletion endpoint will
complain if you give it that does not exist. As this means that we have
no other message to delete in this channel (and message deletes work
per-channel), we can just log an exception and carry on with business.

I will copy my comment from the code, as it explains why we want this:

In the rare case where we found messages matching the spam filter across
multiple channels, it is possible that a single channel will only
contain a single message to delete. If that should be the case,
discord.py will use the "delete single message" endpoint instead of the
bulk delete endpoint, and the single message deletion endpoint will
complain if you give it that does not exist.  As this means that we have
no other message to delete in this channel (and message deletes work
per-channel), we can just log an exception and carry on with business.
@jchristgit
Copy link
Copy Markdown
Contributor Author

Traceback found via pod logs:

2021-09-24 16:34:34 | bot | ERROR | Unhandled exception in on_message.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/bot/bot/exts/filters/antispam.py", line 220, in on_message
    await self.maybe_delete_messages(relevant_messages)
  File "/bot/bot/exts/filters/antispam.py", line 253, in maybe_delete_messages
    await channel.delete_messages(messages)
  File "/usr/local/lib/python3.9/site-packages/discord/channel.py", line 294, in delete_messages
    await self._state.http.delete_message(self.id, message_id)
  File "/usr/local/lib/python3.9/site-packages/discord/http.py", line 250, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message

@jchristgit
Copy link
Copy Markdown
Contributor Author

(This probably also fixes some Sentry issue, but I don't have access to anything there, I will request access to the devops team there)

@ChrisLovering
Copy link
Copy Markdown
Member

(This probably also fixes some Sentry issue, but I don't have access to anything there, I will request access to the devops team there)

added sentry ref to description

@Xithrius Xithrius added a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 2 - normal Normal Priority t: bug Something isn't working labels Sep 24, 2021
@jchristgit jchristgit merged commit 5708818 into main Sep 24, 2021
@jchristgit jchristgit deleted the suppress-notfound-messages-on-delete branch September 24, 2021 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: moderation Related to community moderation functionality: (moderation, defcon, verification) p: 2 - normal Normal Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants