mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-22 10:29:25 +01:00
MessageParser: On syntax error, detail which action caused the error
This can help users debug it.
This commit is contained in:
parent
bb3d456fdf
commit
71ae97ef5e
@ -128,7 +128,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
cursor.execute("UPDATE triggers SET usage_count=? WHERE regexp=?", (old_count + 1, regexp,))
|
||||
db.commit()
|
||||
|
||||
def _runCommandFunction(self, irc, msg, command):
|
||||
def _runCommandFunction(self, irc, msg, command, action_name):
|
||||
"""Run a command from message, as if command was sent over IRC."""
|
||||
try:
|
||||
tokens = callbacks.tokenize(command,
|
||||
@ -136,7 +136,8 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
except SyntaxError as e:
|
||||
# Emulate what callbacks.py does
|
||||
self.log.debug('Error return: %s', utils.exnToString(e))
|
||||
irc.error(str(e))
|
||||
irc.error(format('%s, in %r (triggered by %r)',
|
||||
e, command, action_name))
|
||||
try:
|
||||
self.Proxy(irc.irc, msg, tokens)
|
||||
except Exception as e:
|
||||
@ -200,15 +201,15 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
||||
# Need a lambda to prevent re.sub from
|
||||
# interpreting backslashes in the replacement
|
||||
thisaction = re.sub(r'\$' + str(i+1), lambda _: match.group(i+1), thisaction)
|
||||
actions.append(thisaction)
|
||||
actions.append((regexp, thisaction))
|
||||
if max_triggers != 0 and max_triggers == len(actions):
|
||||
break
|
||||
if max_triggers != 0 and max_triggers == len(actions):
|
||||
break
|
||||
|
||||
|
||||
for action in actions:
|
||||
self._runCommandFunction(irc, msg, action)
|
||||
for (regexp, action) in actions:
|
||||
self._runCommandFunction(irc, msg, action, regexp)
|
||||
|
||||
def doPrivmsg(self, irc, msg):
|
||||
if not callbacks.addressed(irc, msg): #message is not direct command
|
||||
|
@ -89,7 +89,10 @@ class MessageParserTestCase(ChannelPluginTestCase):
|
||||
def testSyntaxError(self):
|
||||
self.assertNotError(r'messageparser add "test" "echo foo \" bar"')
|
||||
self.feedMsg('test')
|
||||
self.assertResponse(' ', 'Error: No closing quotation')
|
||||
self.assertResponse(
|
||||
' ',
|
||||
r"""Error: No closing quotation, in """
|
||||
r"""'echo foo " bar' (triggered by 'test')""")
|
||||
|
||||
def testMatchedBackslashes(self):
|
||||
# Makes sure backslashes in matched arguments are not interpreted
|
||||
|
Loading…
Reference in New Issue
Block a user