From a3a60e6dca8dfd7578755b63099a068072ff4899 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 28 Jan 2022 21:06:31 +0100 Subject: [PATCH] Add proper warnings when applying filters to updates fails --- telethon/_client/updates.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/telethon/_client/updates.py b/telethon/_client/updates.py index c0ba9fa9..2477af9c 100644 --- a/telethon/_client/updates.py +++ b/telethon/_client/updates.py @@ -227,13 +227,18 @@ async def _dispatch(self, update): except Exception: name = getattr(handler.callback, '__name__', repr(handler.callback)) self._log[__name__].exception('Unhandled exception on %s (this is likely a bug in your code)', name) - break - except NotResolved as e: + except NotResolved as nr: try: - await unresolved.resolve() - except Exception: + await nr.unresolved.resolve() + continue + except Exception as e: # we cannot really do much about this; it might be a temporary network issue - warnings.warn(f'failed to resolve filter, handler will be skipped: {e.unresolved!r}') - break + warnings.warn(f'failed to resolve filter, handler will be skipped: {e}: {nr.unresolved!r}') + except Exception as e: + # invalid filter (e.g. types when types were not used as input) + warnings.warn(f'invalid filter applied, handler will be skipped: {e}: {e.filter!r}') + + # we only want to continue on unresolved filter (to check if there are more unresolved) + break self._dispatching_update_handlers = False