From 13bfbeb8595383115e4b382991d5f55f9fac9daa Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Thu, 4 Apr 2019 16:04:26 -0400 Subject: [PATCH] Improve error handling of invalid workflow_engine_parameters --- setup.py | 2 +- wes_service/arvados_wes.py | 5 +++- wes_service/util.py | 54 +++++++++++++++++++++----------------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/setup.py b/setup.py index 706e41c..5f3ea77 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ long_description = readmeFile.read() setup(name='wes-service', - version='3.2', + version='3.3', description='GA4GH Workflow Execution Service reference implementation', long_description=long_description, author='GA4GH Containers and Workflows task team', diff --git a/wes_service/arvados_wes.py b/wes_service/arvados_wes.py index 818d9e5..7eb9866 100644 --- a/wes_service/arvados_wes.py +++ b/wes_service/arvados_wes.py @@ -203,7 +203,10 @@ def RunWorkflow(self, **args): workflow_url = body.get("workflow_url") - project_uuid = body.get("workflow_engine_parameters", {}).get("project_uuid") + workflow_engine_parameters = body.get("workflow_engine_parameters", {}) + project_uuid = None + if workflow_engine_parameters: + project_uuid = workflow_engine_parameters.get("project_uuid") threading.Thread(target=self.invoke_cwl_runner, args=(cr["uuid"], workflow_url, diff --git a/wes_service/util.py b/wes_service/util.py index fd20a15..b0c74eb 100644 --- a/wes_service/util.py +++ b/wes_service/util.py @@ -51,31 +51,37 @@ def collect_attachments(self, run_id=None): body = {} has_attachments = False for k, ls in iterlists(connexion.request.files): - for v in ls: - if k == "workflow_attachment": - sp = v.filename.split("/") - fn = [] - for p in sp: - if p not in ("", ".", ".."): - fn.append(secure_filename(p)) - dest = os.path.join(tempdir, *fn) - if not os.path.isdir(os.path.dirname(dest)): - os.makedirs(os.path.dirname(dest)) - self.log_for_run(run_id, "Staging attachment '%s' to '%s'" % (v.filename, dest)) - v.save(dest) - has_attachments = True - body[k] = "file://%s" % tempdir # Reference to temp working dir. - elif k in ("workflow_params", "tags", "workflow_engine_parameters"): - content = v.read() - body[k] = json.loads(content.decode("utf-8")) - else: - body[k] = v.read().decode() + try: + for v in ls: + if k == "workflow_attachment": + sp = v.filename.split("/") + fn = [] + for p in sp: + if p not in ("", ".", ".."): + fn.append(secure_filename(p)) + dest = os.path.join(tempdir, *fn) + if not os.path.isdir(os.path.dirname(dest)): + os.makedirs(os.path.dirname(dest)) + self.log_for_run(run_id, "Staging attachment '%s' to '%s'" % (v.filename, dest)) + v.save(dest) + has_attachments = True + body[k] = "file://%s" % tempdir # Reference to temp working dir. + elif k in ("workflow_params", "tags", "workflow_engine_parameters"): + content = v.read() + body[k] = json.loads(content.decode("utf-8")) + else: + body[k] = v.read().decode() + except Exception as e: + raise ValueError("Error reading parameter '%s': %s" % (k, e)) for k, ls in iterlists(connexion.request.form): - for v in ls: - if k in ("workflow_params", "tags", "workflow_engine_parameters"): - body[k] = json.loads(v) - else: - body[k] = v + try: + for v in ls: + if k in ("workflow_params", "tags", "workflow_engine_parameters") and v != "": + body[k] = json.loads(v) + else: + body[k] = v + except Exception as e: + raise ValueError("Error reading parameter '%s': %s" % (k, e)) if "workflow_url" in body: if ":" not in body["workflow_url"]: