From c23227cdc73db3d009a18ab8e701aa50ac4bdf95 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 28 Jun 2021 23:10:21 +0200 Subject: [PATCH] MessageParser: Show error when the action has a syntax error Instead of being silent --- plugins/MessageParser/plugin.py | 9 +++++++-- plugins/MessageParser/test.py | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index 604378e36..8e043db70 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -129,8 +129,13 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): def _runCommandFunction(self, irc, msg, command): """Run a command from message, as if command was sent over IRC.""" - tokens = callbacks.tokenize(command, - channel=msg.channel, network=irc.network) + try: + tokens = callbacks.tokenize(command, + channel=msg.channel, network=irc.network) + except SyntaxError as e: + # Emulate what callbacks.py does + self.log.debug('Error return: %s', utils.exnToString(e)) + irc.error(str(e)) try: self.Proxy(irc.irc, msg, tokens) except Exception as e: diff --git a/plugins/MessageParser/test.py b/plugins/MessageParser/test.py index 61c77a910..f08abde49 100644 --- a/plugins/MessageParser/test.py +++ b/plugins/MessageParser/test.py @@ -85,6 +85,11 @@ class MessageParserTestCase(ChannelPluginTestCase): self.assertResponse(' ', '$1') self.assertNotError('messageparser remove "this( .+)? a(.*)"') + def testSyntaxError(self): + self.assertNotError(r'messageparser add "test" "echo foo \" bar"') + self.feedMsg('test') + self.assertResponse(' ', 'Error: No closing quotation') + def testShow(self): self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertRegexp('messageparser show "nostuff"', 'there is no such regexp trigger')