MessageParser: Show error when the action has a syntax error

Instead of being silent
This commit is contained in:
Valentin Lorentz 2021-06-28 23:10:21 +02:00
parent 6b72672a1e
commit c23227cdc7
2 changed files with 12 additions and 2 deletions

View File

@ -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:

View File

@ -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')