From 0f71c817320c077463a483701c6d51a8fa3e2164 Mon Sep 17 00:00:00 2001 From: MarkKoz Date: Tue, 3 Dec 2019 20:29:23 -0800 Subject: Utils: log send_attachments failures instead of raising exceptions --- bot/utils/messages.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index 232d3cba6..a39521b72 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -1,5 +1,6 @@ import asyncio import contextlib +import logging from io import BytesIO from typing import List, Optional, Sequence, Union @@ -9,6 +10,8 @@ from discord.errors import HTTPException from bot.constants import Emojis +log = logging.getLogger(__name__) + async def wait_for_deletion( message: Message, @@ -64,6 +67,10 @@ async def send_attachments( large = [] urls = [] for attachment in message.attachments: + failure_msg = ( + f"Failed to re-upload attachment {attachment.filename} from message {message.id}" + ) + try: # Allow 512 bytes of leeway for the rest of the request. # This should avoid most files that are too large, @@ -84,11 +91,13 @@ async def send_attachments( ) elif link_large: large.append(attachment) + else: + log.warning(f"{failure_msg} because it's too large.") except HTTPException as e: if link_large and e.status == 413: large.append(attachment) else: - raise + log.warning(f"{failure_msg} with status {e.status}.") if link_large and large: desc = f"\n".join(f"[{attachment.filename}]({attachment.url})" for attachment in large) -- cgit v1.2.3