diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index 40cefbb7..ca4da7cd 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -318,7 +318,7 @@ class AbstractUser(ABC): try: users = (entity for entity in entities.values() if isinstance(entity, User)) puppets = ((pu.Puppet.get(TelegramID(user.id)), user) for user in users) - await asyncio.gather(*[puppet.update_info(self, info) + await asyncio.gather(*[puppet.try_update_info(self, info) for puppet, info in puppets if puppet]) except Exception: self.log.exception("Failed to handle entity updates") diff --git a/mautrix_telegram/commands/portal/admin.py b/mautrix_telegram/commands/portal/admin.py index 7388251b..458740a6 100644 --- a/mautrix_telegram/commands/portal/admin.py +++ b/mautrix_telegram/commands/portal/admin.py @@ -61,7 +61,7 @@ async def clear_db_cache(evt: CommandEvent) -> EventID: for puppet in pu.Puppet.by_custom_mxid.values(): puppet.sync_task.cancel() pu.Puppet.by_custom_mxid = {} - await asyncio.gather(*[puppet.start() for puppet in pu.Puppet.all_with_custom_mxid()], + await asyncio.gather(*[puppet.try_start() for puppet in pu.Puppet.all_with_custom_mxid()], loop=evt.loop) await evt.reply("Cleared puppet cache and restarted custom puppet syncers") elif section == "user": diff --git a/mautrix_telegram/portal/metadata.py b/mautrix_telegram/portal/metadata.py index c3acda3c..df1b8102 100644 --- a/mautrix_telegram/portal/metadata.py +++ b/mautrix_telegram/portal/metadata.py @@ -226,7 +226,11 @@ class PortalMetadata(BasePortal, ABC): if self.mxid: if update_if_exists: if not entity: - entity = await self.get_entity(user) + try: + entity = await self.get_entity(user) + except Exception: + self.log.exception(f"Failed to get entity through {user.tgid} for update") + return self.mxid update = self.update_matrix_room(user, entity, self.peer_type == "user") if synchronous: await update diff --git a/mautrix_telegram/puppet.py b/mautrix_telegram/puppet.py index f20cd655..cb53d753 100644 --- a/mautrix_telegram/puppet.py +++ b/mautrix_telegram/puppet.py @@ -226,6 +226,12 @@ class Puppet(CustomPuppetMixin): return name return cls.displayname_template.format_full(name) + async def try_update_info(self, source: 'AbstractUser', info: User) -> None: + try: + await self.update_info(source, info) + except Exception: + source.log.exception(f"Failed to update info of {self.tgid}") + async def update_info(self, source: 'AbstractUser', info: User) -> None: if self.disable_updates: return