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:
Lonami Exo
2022-05-23 14:02:56 +02:00
parent 06b0ae56d4
commit 6005585764
2 changed files with 18 additions and 3 deletions

View File

@@ -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,