From fb9fb681308282d0952f93f5dedb34e998c9e666 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Thu, 15 Nov 2018 02:56:53 +0300 Subject: [PATCH] Check error handler callback args to prevent cycled exceptions --- aiogram/dispatcher/dispatcher.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 6247f211..3f7c0d9b 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -4,6 +4,7 @@ import itertools import logging import time import typing +from inspect import signature from .filters import Command, ContentTypeFilter, ExceptionsFilter, FiltersFactory, FuncFilter, HashTag, Regexp, \ RegexpCommandsFilter, StateFilter, Text @@ -812,6 +813,12 @@ class Dispatcher(DataMixin, ContextInstanceMixin): :param exception: you can make handler for specific errors type :param run_task: run callback in task (no wait results) """ + + # Check number of arguments of the callback, cause only two arguments accepted. + sig = signature(callback) + if len(sig.parameters) != 2: + raise RuntimeError('Errors handlers should accept only two arguments (current update and exception)') + filters_set = self.filters_factory.resolve(self.errors_handlers, *custom_filters, exception=exception, @@ -827,6 +834,7 @@ class Dispatcher(DataMixin, ContextInstanceMixin): :return: """ + def decorator(callback): self.register_errors_handler(self._wrap_async_task(callback, run_task), *custom_filters, exception=exception, **kwargs)