Skip to content

Commit

Permalink
build(restapi): add errors to workflow validation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhand committed Oct 4, 2024
1 parent 1ba3e30 commit 47cced6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/dioptra/restapi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions src/dioptra/restapi/v1/workflows/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
11 changes: 3 additions & 8 deletions src/dioptra/restapi/v1/workflows/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
log.debug("Entrypoint workflow validation failed", issues=issues)
raise EntrypointWorkflowValidationIssue(issues)

0 comments on commit 47cced6

Please sign in to comment.