mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +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
|
# inserted because this is a rather expensive operation
|
||||||
# (default's sqlite3 takes ~0.1s to commit changes). Do
|
# (default's sqlite3 takes ~0.1s to commit changes). Do
|
||||||
# it every minute instead. No-op if there's nothing new.
|
# it every minute instead. No-op if there's nothing new.
|
||||||
|
try:
|
||||||
await self.session.save()
|
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):
|
async def _dispatch_update(self: 'TelegramClient', update):
|
||||||
# TODO only used for AlbumHack, and MessageBox is not really designed for this
|
# TODO only used for AlbumHack, and MessageBox is not really designed for this
|
||||||
|
|
|
@ -71,7 +71,11 @@ class UserMethods:
|
||||||
exceptions.append(e)
|
exceptions.append(e)
|
||||||
results.append(None)
|
results.append(None)
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
await self.session.process_entities(result)
|
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)
|
self._entity_cache.add(result)
|
||||||
exceptions.append(None)
|
exceptions.append(None)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
@ -82,7 +86,14 @@ class UserMethods:
|
||||||
return results
|
return results
|
||||||
else:
|
else:
|
||||||
result = await future
|
result = await future
|
||||||
|
# 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)
|
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)
|
self._entity_cache.add(result)
|
||||||
return result
|
return result
|
||||||
except (errors.ServerError, errors.RpcCallFailError,
|
except (errors.ServerError, errors.RpcCallFailError,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user