From b41435f4079026afd546b36ae3bdbf8d5b144982 Mon Sep 17 00:00:00 2001 From: abdullaev388 Date: Wed, 16 Feb 2022 12:29:27 +0500 Subject: [PATCH] more descriptive exceptions --- telebot/asyncio_filters.py | 10 +++++----- telebot/custom_filters.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/telebot/asyncio_filters.py b/telebot/asyncio_filters.py index a8b7180..cb0120b 100644 --- a/telebot/asyncio_filters.py +++ b/telebot/asyncio_filters.py @@ -61,16 +61,16 @@ class TextFilter: raise ValueError('None of the check modes was specified') self.equals = equals - self.contains = self._check_iterable(contains) - self.starts_with = self._check_iterable(starts_with) - self.ends_with = self._check_iterable(ends_with) + self.contains = self._check_iterable(contains, filter_name='contains') + self.starts_with = self._check_iterable(starts_with, filter_name='starts_with') + self.ends_with = self._check_iterable(ends_with, filter_name='ends_with') self.ignore_case = ignore_case - def _check_iterable(self, iterable): + def _check_iterable(self, iterable, filter_name): if not iterable: pass elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple): - raise ValueError + raise ValueError(f"Incorrect value of {filter_name!r}") elif isinstance(iterable, str): iterable = [iterable] elif isinstance(iterable, list) or isinstance(iterable, tuple): diff --git a/telebot/custom_filters.py b/telebot/custom_filters.py index 145cc74..e6a1531 100644 --- a/telebot/custom_filters.py +++ b/telebot/custom_filters.py @@ -61,16 +61,16 @@ class TextFilter: raise ValueError('None of the check modes was specified') self.equals = equals - self.contains = self._check_iterable(contains) - self.starts_with = self._check_iterable(starts_with) - self.ends_with = self._check_iterable(ends_with) + self.contains = self._check_iterable(contains, filter_name='contains') + self.starts_with = self._check_iterable(starts_with, filter_name='starts_with') + self.ends_with = self._check_iterable(ends_with, filter_name='ends_with') self.ignore_case = ignore_case - def _check_iterable(self, iterable): + def _check_iterable(self, iterable, filter_name: str): if not iterable: pass elif not isinstance(iterable, str) and not isinstance(iterable, list) and not isinstance(iterable, tuple): - raise ValueError + raise ValueError(f"Incorrect value of {filter_name!r}") elif isinstance(iterable, str): iterable = [iterable] elif isinstance(iterable, list) or isinstance(iterable, tuple):