improve clarity and exception messaging
This commit is contained in:
parent
e985d310e2
commit
4c961db076
|
@ -2,6 +2,7 @@ import os
|
||||||
from .plugin import Plugin
|
from .plugin import Plugin
|
||||||
from .messenger import Messenger
|
from .messenger import Messenger
|
||||||
from .context import Context
|
from .context import Context
|
||||||
|
import traceback
|
||||||
|
|
||||||
class Dispatcher(object):
|
class Dispatcher(object):
|
||||||
def __init__(self, base_directory, only=None, skip=None):
|
def __init__(self, base_directory, only=None, skip=None):
|
||||||
|
@ -21,30 +22,35 @@ class Dispatcher(object):
|
||||||
def dispatch(self, tasks):
|
def dispatch(self, tasks):
|
||||||
success = True
|
success = True
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
for action in task:
|
for action in task.keys():
|
||||||
if (self._only is not None and action not in self._only \
|
if (self._only is not None and action not in self._only \
|
||||||
or self._skip is not None and action in self._skip) \
|
or self._skip is not None and action in self._skip) \
|
||||||
and action != 'defaults':
|
and action != 'defaults':
|
||||||
self._log.info('Skipping action %s' % action)
|
self._log.info('Skipping action %s' % action)
|
||||||
continue
|
continue
|
||||||
handled = False
|
handled = False
|
||||||
|
# print("\tcurrent action", action)
|
||||||
if action == 'defaults':
|
if action == 'defaults':
|
||||||
self._context.set_defaults(task[action]) # replace, not update
|
self._context.set_defaults(task[action]) # replace, not update
|
||||||
handled = True
|
handled = True
|
||||||
# keep going, let other plugins handle this if they want
|
# keep going, let other plugins handle this if they want
|
||||||
for plugin in self._plugins:
|
for plugin in self._plugins:
|
||||||
|
|
||||||
if plugin.can_handle(action):
|
if plugin.can_handle(action):
|
||||||
|
# print("Action:", action)
|
||||||
try:
|
try:
|
||||||
success &= plugin.handle(action, task[action])
|
success &= plugin.handle(action, task[action])
|
||||||
handled = True
|
handled = True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
print("failure", err)
|
||||||
|
traceback.print_exception(type(err), err, err.__traceback__)
|
||||||
self._log.error(
|
self._log.error(
|
||||||
'An error was encountered while executing action %s' %
|
'An error was encountered while executing action "%s"' %
|
||||||
action)
|
action)
|
||||||
self._log.debug(err)
|
self._log.debug(err)
|
||||||
if not handled:
|
if not handled:
|
||||||
success = False
|
success = False
|
||||||
self._log.error('Action %s not handled' % action)
|
self._log.error('Action "%s" not handled' % action)
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def _load_plugins(self):
|
def _load_plugins(self):
|
||||||
|
|
Loading…
Reference in a new issue