diff --git a/src/rkd/__init__.py b/src/rkd/__init__.py index 90e89d5e..42306fb4 100644 --- a/src/rkd/__init__.py +++ b/src/rkd/__init__.py @@ -6,6 +6,7 @@ from .resolver import TaskResolver from .validator import TaskDeclarationValidator from .executor import OneByOneTaskExecutor +from .exception import TaskNotFoundException class RiotKitDoApplication: @@ -13,20 +14,25 @@ class RiotKitDoApplication: _tasks_to_execute = [] def main(self): + try: + # load context of components + self._ctx = ContextFactory().create_unified_context() - # load context of components - self._ctx = ContextFactory().create_unified_context() - resolver = TaskResolver(self._ctx) - executor = OneByOneTaskExecutor(self._ctx) + resolver = TaskResolver(self._ctx) + executor = OneByOneTaskExecutor(self._ctx) - # iterate over each task, parse commandline arguments - requested_tasks = CommandlineParsingHelper.create_grouped_arguments([':init'] + sys.argv[1:]) + # iterate over each task, parse commandline arguments + requested_tasks = CommandlineParsingHelper.create_grouped_arguments([':init'] + sys.argv[1:]) - # validate all tasks - resolver.resolve(requested_tasks, TaskDeclarationValidator.assert_declaration_is_valid) + # validate all tasks + resolver.resolve(requested_tasks, TaskDeclarationValidator.assert_declaration_is_valid) - # execute all tasks - resolver.resolve(requested_tasks, executor.execute) + # execute all tasks + resolver.resolve(requested_tasks, executor.execute) + + except TaskNotFoundException as e: + print(e) + sys.exit(1) executor.get_observer().execution_finished() diff --git a/src/rkd/context.py b/src/rkd/context.py index 5b9ff401..e1e07042 100644 --- a/src/rkd/context.py +++ b/src/rkd/context.py @@ -6,6 +6,7 @@ from .contract import ContextInterface from .argparsing import CommandlineParsingHelper from .inputoutput import SystemIO +from .exception import TaskNotFoundException CURRENT_SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -66,8 +67,8 @@ def find_task_by_name(self, name: str) -> Union[TaskDeclaration, GroupDeclaratio try: return self._compiled[name] except KeyError: - raise Exception(('Task "%s" is not defined. Check if it is defined, or' + - ' imported, or if the spelling is correct.') % name) + raise TaskNotFoundException(('Task "%s" is not defined. Check if it is defined, or' + + ' imported, or if the spelling is correct.') % name) def find_all_tasks(self) -> Dict[str, Union[TaskDeclaration, GroupDeclaration]]: return self._compiled diff --git a/src/rkd/exception.py b/src/rkd/exception.py new file mode 100644 index 00000000..4821120d --- /dev/null +++ b/src/rkd/exception.py @@ -0,0 +1,9 @@ + + +class ContextException(Exception): + pass + + +class TaskNotFoundException(ContextException): + pass +