Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
WIP add error handling for non-existing tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Apr 30, 2020
1 parent 6b63e16 commit 50fe0d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/rkd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,33 @@
from .resolver import TaskResolver
from .validator import TaskDeclarationValidator
from .executor import OneByOneTaskExecutor
from .exception import TaskNotFoundException


class RiotKitDoApplication:
_ctx: Context
_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()

Expand Down
5 changes: 3 additions & 2 deletions src/rkd/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/rkd/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


class ContextException(Exception):
pass


class TaskNotFoundException(ContextException):
pass

0 comments on commit 50fe0d0

Please sign in to comment.