mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Don't crash if periodic session access fails
If saving every minute or new entities fails, it's not fatal. Other places are not checked because it is more critical for information to be saved, such as disconnect, where we want to crash if the session cannot be accessed.
This commit is contained in:
parent
06b0ae56d4
commit
6005585764
|
@ -393,7 +393,11 @@ class UpdateMethods:
|
|||
# inserted because this is a rather expensive operation
|
||||
# (default's sqlite3 takes ~0.1s to commit changes). Do
|
||||
# it every minute instead. No-op if there's nothing new.
|
||||
await self.session.save()
|
||||
try:
|
||||
await self.session.save()
|
||||
except OSError as e:
|
||||
# No big deal if this cannot be immediately saved
|
||||
self._log[__name__].warning('Could not perform the periodic save of session data: %s: %s', type(e), e)
|
||||
|
||||
async def _dispatch_update(self: 'TelegramClient', update):
|
||||
# TODO only used for AlbumHack, and MessageBox is not really designed for this
|
||||
|
|
|
@ -71,7 +71,11 @@ class UserMethods:
|
|||
exceptions.append(e)
|
||||
results.append(None)
|
||||
continue
|
||||
await self.session.process_entities(result)
|
||||
try:
|
||||
await self.session.process_entities(result)
|
||||
except OSError:
|
||||
self._log[__name__].warning(
|
||||
'Failed to save possibly new entities to the session: %s: %s', type(e), e)
|
||||
self._entity_cache.add(result)
|
||||
exceptions.append(None)
|
||||
results.append(result)
|
||||
|
@ -82,7 +86,14 @@ class UserMethods:
|
|||
return results
|
||||
else:
|
||||
result = await future
|
||||
await self.session.process_entities(result)
|
||||
# This is called pretty often, and it's okay if it fails every now and then.
|
||||
# It only means certain entities won't be saved.
|
||||
try:
|
||||
await self.session.process_entities(result)
|
||||
except OSError:
|
||||
self._log[__name__].warning(
|
||||
'Failed to save possibly new entities to the session: %s: %s', type(e), e)
|
||||
|
||||
self._entity_cache.add(result)
|
||||
return result
|
||||
except (errors.ServerError, errors.RpcCallFailError,
|
||||
|
|
Loading…
Reference in New Issue
Block a user