From 47cced65bc07165473d13bd981afde9874ec1f3d Mon Sep 17 00:00:00 2001 From: Andrew Hand Date: Fri, 4 Oct 2024 10:15:00 -0400 Subject: [PATCH] build(restapi): add errors to workflow validation --- src/dioptra/restapi/errors.py | 1 + src/dioptra/restapi/v1/workflows/errors.py | 11 +++++++++++ src/dioptra/restapi/v1/workflows/service.py | 11 +++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/dioptra/restapi/errors.py b/src/dioptra/restapi/errors.py index ba72c03a5..1ba834aaf 100644 --- a/src/dioptra/restapi/errors.py +++ b/src/dioptra/restapi/errors.py @@ -104,3 +104,4 @@ def register_error_handlers(api: Api) -> None: v1.queues.errors.register_error_handlers(api) v1.tags.errors.register_error_handlers(api) v1.users.errors.register_error_handlers(api) + v1.workflows.errors.register_error_handlers(api) diff --git a/src/dioptra/restapi/v1/workflows/errors.py b/src/dioptra/restapi/v1/workflows/errors.py index c5723ec4a..e482bb05b 100644 --- a/src/dioptra/restapi/v1/workflows/errors.py +++ b/src/dioptra/restapi/v1/workflows/errors.py @@ -28,6 +28,10 @@ class JobExperimentDoesNotExistError(Exception): """The experiment associated with the job does not exist.""" +class EntrypointWorkflowValidationIssue(Exception): + """The entrypoint workflow yaml has issues.""" + + def register_error_handlers(api: Api) -> None: @api.errorhandler(JobEntryPointDoesNotExistError) def handle_experiment_job_does_not_exist_error(error): @@ -39,3 +43,10 @@ def handle_experiment_does_not_exist_error(error): "message": "Not Found - The experiment associated with the job does not " "exist" }, 404 + + @api.errorhandler(EntrypointWorkflowValidationIssue) + def handle_entrypoint_workflow_validation_error(error): + issues = error.args + print (issues) + message = "\n".join(str(issue) for issue in issues) + return {"message": message}, 422 \ No newline at end of file diff --git a/src/dioptra/restapi/v1/workflows/service.py b/src/dioptra/restapi/v1/workflows/service.py index 6f0d396c7..e4fb8dc99 100644 --- a/src/dioptra/restapi/v1/workflows/service.py +++ b/src/dioptra/restapi/v1/workflows/service.py @@ -25,6 +25,7 @@ from .lib import package_job_files, views from .schema import FileTypes +from .errors import EntrypointWorkflowValidationIssue from dioptra.restapi.db import db from dioptra.restapi.v1 import utils @@ -133,7 +134,6 @@ def validate( plugins = self._plugin_id_service.get(plugin_ids) for plugin in plugins: for plugin_file in plugin['plugin_files']: - # print(plugin_file.tasks) for task in plugin_file.tasks: input_parameters = task.input_parameters output_parameters = task.output_parameters @@ -159,16 +159,11 @@ def validate( "tasks": tasks, "graph": cast(dict[str, Any], yaml.safe_load(task_graph)), } - print (task_engine_dict) valid = is_valid(task_engine_dict) if valid: return {"status": "Success", "valid": valid} else: issues = validate(task_engine_dict) - print(issues) - return { - "status": "Success", - "valid": valid, - # "issues": issues, - } \ No newline at end of file + log.debug("Entrypoint workflow validation failed", issues=issues) + raise EntrypointWorkflowValidationIssue(issues) \ No newline at end of file