From 5a8c066ff7b6b75b88efa524b52dc709a5683959 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 28 Sep 2021 21:07:15 +0200 Subject: [PATCH] Fix generated RpcError were no longer formatting the value --- telethon/errors/_rpcbase.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/telethon/errors/_rpcbase.py b/telethon/errors/_rpcbase.py index d074be26..c67c6ebf 100644 --- a/telethon/errors/_rpcbase.py +++ b/telethon/errors/_rpcbase.py @@ -17,6 +17,10 @@ _NESTS_QUERY = ( class RpcError(Exception): def __init__(self, code, message, request=None): + # Special-case '2fa' to exclude the 2 from values + self.values = [int(x) for x in re.findall(r'-?\d+', re.sub(r'^2fa', '', message, flags=re.IGNORECASE))] + self.value = self.values[0] if self.values else None + doc = self.__doc__ if doc is None: doc = ( @@ -25,14 +29,13 @@ class RpcError(Exception): ) elif not doc: doc = '(no description available)' + elif self.value: + doc = re.sub(r'{(\w+)}', str(self.value), doc) super().__init__(f'{message}, code={code}{self._fmt_request(request)}: {doc}') self.code = code self.message = message self.request = request - # Special-case '2fa' to exclude the 2 from values - self.values = [int(x) for x in re.findall(r'-?\d+', re.sub(r'^2fa', '', self.message, flags=re.IGNORECASE))] - self.value = self.values[0] if self.values else None @staticmethod def _fmt_request(request):