From 9a8c76fc2b5f7f0664a7487063bd8f3244fccb7c Mon Sep 17 00:00:00 2001 From: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Date: Fri, 31 Dec 2021 16:04:21 +0100 Subject: [PATCH] Improve Error Messages in CommandHandler.__init__ (#2837) --- telegram/ext/_commandhandler.py | 2 +- tests/test_commandhandler.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/telegram/ext/_commandhandler.py b/telegram/ext/_commandhandler.py index 02cf6152d..5a762ba80 100644 --- a/telegram/ext/_commandhandler.py +++ b/telegram/ext/_commandhandler.py @@ -97,7 +97,7 @@ class CommandHandler(Handler[Update, CCT]): self.command = [x.lower() for x in command] for comm in self.command: if not re.match(r'^[\da-z_]{1,32}$', comm): - raise ValueError('Command is not a valid bot command') + raise ValueError(f'Command `{comm}` is not a valid bot command') self.filters = filters if filters is not None else filters_module.UpdateType.MESSAGES diff --git a/tests/test_commandhandler.py b/tests/test_commandhandler.py index 5dbf8005b..d2622e892 100644 --- a/tests/test_commandhandler.py +++ b/tests/test_commandhandler.py @@ -173,7 +173,9 @@ class TestCommandHandler(BaseTest): ids=['too long', 'invalid letter', 'invalid characters'], ) def test_invalid_commands(self, cmd): - with pytest.raises(ValueError, match='not a valid bot command'): + with pytest.raises( + ValueError, match=f'`{re.escape(cmd.lower())}` is not a valid bot command' + ): CommandHandler(cmd, self.callback_basic) def test_command_list(self):