diff --git a/telethon/client/messageparse.py b/telethon/client/messageparse.py index 640b3001..741adadb 100644 --- a/telethon/client/messageparse.py +++ b/telethon/client/messageparse.py @@ -142,18 +142,23 @@ class MessageParseMethods(UserMethods): random_id = request if isinstance(request, int) else request.random_id if not utils.is_list_like(random_id): - if random_id in random_to_id: - return id_to_message[random_to_id[random_id]] - else: - return None - else: - # ``rnd in random_to_id`` is needed because trying to forward only - # deleted messages causes `MESSAGE_ID_INVALID`, but forwarding - # valid and invalid messages in the same call makes the call - # succeed, although the API won't return those messages thus - # `random_to_id[rnd]` would `KeyError`. - return [id_to_message[random_to_id[rnd]] - if rnd in random_to_id else None - for rnd in random_id] + msg = id_to_message.get(random_to_id.get(random_id)) + if not msg: + self._log[__name__].warning( + 'Request %s had missing message mapping %s', request, result) + + return msg + + try: + return [id_to_message[random_to_id[rnd]] for rnd in random_id] + except KeyError: + # Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets + # deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at + # Telegram), in which case we get some "missing" message mappings. + # Log them with the hope that we can better work around them. + self._log[__name__].warning( + 'Request %s had missing message mappings %s', request, result) + + return [id_to_message.get(random_to_id.get(rnd)) for rnd in random_to_id] # endregion diff --git a/telethon_generator/data/errors.csv b/telethon_generator/data/errors.csv index 6439ea53..7a43231b 100644 --- a/telethon_generator/data/errors.csv +++ b/telethon_generator/data/errors.csv @@ -270,4 +270,5 @@ WALLPAPER_INVALID,400,The input wallpaper was not valid WC_CONVERT_URL_INVALID,400,WC convert URL invalid WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL WEBPAGE_MEDIA_EMPTY,400,Webpage media empty +WORKER_BUSY_TOO_LONG_RETRY,500,Telegram workers are too busy to respond immediately YOU_BLOCKED_USER,400,You blocked this user