From 0b6b59805934a1897324b306cab066539f539941 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 24 Aug 2018 17:39:55 +0200 Subject: [PATCH] Log unknown constructors --- pyrogram/api/core/object.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyrogram/api/core/object.py b/pyrogram/api/core/object.py index a1e20726..3cf12329 100644 --- a/pyrogram/api/core/object.py +++ b/pyrogram/api/core/object.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from collections import OrderedDict from datetime import datetime from io import BytesIO @@ -23,13 +24,23 @@ from json import JSONEncoder, dumps from ..all import objects +log = logging.getLogger(__name__) + class Object: all = {} @staticmethod def read(b: BytesIO, *args): - return Object.all[int.from_bytes(b.read(4), "little")].read(b, *args) + constructor_id = int.from_bytes(b.read(4), "little") + + try: + return Object.all[constructor_id].read(b, *args) + except KeyError: + log.error("Unknown constructor found: {}. Full data: {}".format( + hex(constructor_id), + b.getvalue().hex()) + ) def write(self, *args) -> bytes: pass