From dea091ee5370dfd3af956b93132d60efdea07157 Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Mon, 18 Apr 2016 19:16:31 +0100 Subject: [PATCH] Improve error handling for invalid commands --- beetsplug/hook.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/beetsplug/hook.py b/beetsplug/hook.py index a32247bf8..4f38a7b9c 100644 --- a/beetsplug/hook.py +++ b/beetsplug/hook.py @@ -45,23 +45,20 @@ class HookPlugin(BeetsPlugin): def create_and_register_hook(self, event, command): def hook_function(**kwargs): + if command is None or len(command) == 0: + self._log.error('invalid command "{0}"', command) + return + formatted_command = command.format(event=event, **kwargs) encoded_command = formatted_command.decode(_arg_encoding()) command_pieces = shlex.split(encoded_command) - if len(command_pieces) == 0: - raise ConfigValueError('invalid command "{0}"'.format( - command)) - - self._log.debug('Running command "{0}" for event "{1}"', + self._log.debug('Running command "{0}" for event {1}', encoded_command, event) try: subprocess.Popen(command_pieces).wait() - except OSError as e: - _, _, trace = sys.exc_info() - message = '{0}: {1}'.format(e, command_pieces[0]) - - raise OSError, message, trace + except OSError as exc: + self._log.error('hook for {0} failed: {1}', event, exc) self.register_listener(event, hook_function)