Add proper warnings when applying filters to updates fails

This commit is contained in:
Lonami Exo 2022-01-28 21:06:31 +01:00
parent 055eca49ea
commit a3a60e6dca

View File

@ -227,13 +227,18 @@ async def _dispatch(self, update):
except Exception: except Exception:
name = getattr(handler.callback, '__name__', repr(handler.callback)) 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) self._log[__name__].exception('Unhandled exception on %s (this is likely a bug in your code)', name)
break except NotResolved as nr:
except NotResolved as e:
try: try:
await unresolved.resolve() await nr.unresolved.resolve()
except Exception: continue
except Exception as e:
# we cannot really do much about this; it might be a temporary network issue # 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}') warnings.warn(f'failed to resolve filter, handler will be skipped: {e}: {nr.unresolved!r}')
break 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 self._dispatching_update_handlers = False