From 1e94fe25fa399d196f004a26fc4fb3b82dba9bfd Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 20 Feb 2020 13:40:08 +0100 Subject: [PATCH] Log requests that trigger struct.error The exception hardly provides any valuable information. This will hopefully help troubleshooting why the error happens. --- telethon/network/mtprotosender.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 8ed24cc3..5483716a 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -1,5 +1,6 @@ import asyncio import collections +import struct from . import authenticator from ..extensions.messagepacker import MessagePacker @@ -169,7 +170,14 @@ class MTProtoSender: raise ConnectionError('Cannot send requests while disconnected') if not utils.is_list_like(request): - state = RequestState(request, self._loop) + try: + state = RequestState(request, self._loop) + except struct.error as e: + # "struct.error: required argument is not an integer" is not + # very helpful; log the request to find out what wasn't int. + self._log.error('Request caused struct.error: %s: %s', e, request) + raise + self._send_queue.append(state) return state.future else: @@ -177,7 +185,12 @@ class MTProtoSender: futures = [] state = None for req in request: - state = RequestState(req, self._loop, after=ordered and state) + try: + state = RequestState(req, self._loop, after=ordered and state) + except struct.error as e: + self._log.error('Request caused struct.error: %s: %s', e, request) + raise + states.append(state) futures.append(state.future)