From 6fafc533ab1d23d6da8339be2e5c8c87ca2592f4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 20 Oct 2023 01:03:42 +0300 Subject: [PATCH] Catch AuthKeyNotFound in start --- mautrix_telegram/user.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 3f6d35a0..9a524213 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -23,6 +23,7 @@ import time from telethon.errors import ( AuthKeyDuplicatedError, AuthKeyError, + AuthKeyNotFound, RPCError, TakeoutInitDelayError, UnauthorizedError, @@ -215,7 +216,7 @@ class User(DBUser, AbstractUser, BaseUser): async with self._ensure_started_lock: return cast(User, await super().ensure_started(even_if_no_session)) - async def on_signed_out(self, err: UnauthorizedError | AuthKeyError) -> None: + async def on_signed_out(self, err: UnauthorizedError | AuthKeyError | AuthKeyNotFound) -> None: error_code = "tg-auth-error" if isinstance(err, AuthKeyDuplicatedError): error_code = "tg-auth-key-duplicated" @@ -236,8 +237,8 @@ class User(DBUser, AbstractUser, BaseUser): async def start(self, delete_unless_authenticated: bool = False) -> User: try: await super().start() - except AuthKeyDuplicatedError as e: - self.log.warning("Got AuthKeyDuplicatedError in start()") + except (AuthKeyDuplicatedError, AuthKeyNotFound) as e: + self.log.warning(f"Got {type(e).__name__} in start()") await self.on_signed_out(e) if not delete_unless_authenticated: # The caller wants the client to be connected, so restart the connection.