From 68158d10538a1696a4f079601f39173bee673c6a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Nov 2020 12:41:06 +0100 Subject: [PATCH] Add nicer error in case of unknown constructors --- pyrogram/raw/core/tl_object.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyrogram/raw/core/tl_object.py b/pyrogram/raw/core/tl_object.py index 48b3ec91..de596a8b 100644 --- a/pyrogram/raw/core/tl_object.py +++ b/pyrogram/raw/core/tl_object.py @@ -30,7 +30,16 @@ class TLObject: @classmethod def read(cls, data: BytesIO, *args: Any) -> Any: - return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args) + try: + return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args) + except KeyError as e: + left = data.read() + + left = [left[i:i + 64] for i in range(0, len(left), 64)] + left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left] + left = "\n".join(" ".join(x for x in left) for left in left) + + raise ValueError(f"Unknown constructor found: {hex(e.args[0])}\n{left}") def write(self, *args: Any) -> bytes: pass