diff --git a/earwigbot/commands/__init__.py b/earwigbot/commands/__init__.py index 33604f1..f50094e 100644 --- a/earwigbot/commands/__init__.py +++ b/earwigbot/commands/__init__.py @@ -57,10 +57,22 @@ class BaseCommand(object): self.config = bot.config self.logger = bot.commands.logger.getChild(self.name) + def _wrap_check(self, data): + """Check whether this command should be called, catching errors.""" + try: + return self.check(data) + except Exception: + e = "Error checking command '{0}' with data: {1}:" + self.logger.exception(e.format(self.name, data)) + def _wrap_process(self, data): - """Make a quick connection alias and then process() the message.""" + """Make a connection alias, process() the message, and catch errors.""" self.connection = self.bot.frontend - self.process(data) + try: + self.process(data) + except Exception: + e = "Error executing command '{0}':" + self.logger.exception(e.format(data.command)) def check(self, data): """Return whether this command should be called in response to 'data'. diff --git a/earwigbot/managers.py b/earwigbot/managers.py index 0802516..28da7d6 100644 --- a/earwigbot/managers.py +++ b/earwigbot/managers.py @@ -149,16 +149,13 @@ class CommandManager(_ResourceManager): def check(self, hook, data): """Given an IRC event, check if there's anything we can respond to.""" - with self.lock: - for command in self._resources.itervalues(): - if hook in command.hooks: - if command.check(data): - try: - command._wrap_process(data) - except Exception: - e = "Error executing command '{0}':" - self.logger.exception(e.format(data.command)) - break + self.lock.acquire() + for command in self._resources.itervalues(): + if hook in command.hooks and command._wrap_check(data): + self.lock.release() + command._wrap_process(data) + return + self.lock.release() class TaskManager(_ResourceManager):