Skip to content

Commit

Permalink
Merge pull request #70 from common-workflow-language/error-reporting
Browse files Browse the repository at this point in the history
Improve error reporting for bad requests
  • Loading branch information
tetron authored Feb 13, 2019
2 parents 207b971 + 042d582 commit 4c03521
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
long_description = readmeFile.read()

setup(name='wes-service',
version='3.1',
version='3.2',
description='GA4GH Workflow Execution Service reference implementation',
long_description=long_description,
author='GA4GH Containers and Workflows task team',
Expand Down
13 changes: 11 additions & 2 deletions wes_service/arvados_wes.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def RunWorkflow(self, **args):
"output_path": "n/a",
"priority": 500}}).execute()

success = False
try:
tempdir, body = self.collect_attachments(cr["uuid"])

Expand All @@ -210,14 +211,22 @@ def RunWorkflow(self, **args):
env,
project_uuid,
tempdir)).start()

success = True
except ValueError as e:
self.log_for_run(cr["uuid"], "Bad request: " + str(e))
cr = api.container_requests().update(uuid=cr["uuid"],
body={"container_request":
{"priority": 0}}).execute()
return {"msg": str(e), "status_code": 400}, 400
except Exception as e:
logging.exception("Error")
self.log_for_run(cr["uuid"], "An exception ocurred while handling your request: " + str(e))
cr = api.container_requests().update(uuid=cr["uuid"],
body={"container_request":
{"priority": 0}}).execute()
return {"run_id": cr["uuid"]}
return {"msg": str(e), "status_code": 500}, 500
else:
return {"run_id": cr["uuid"]}

@catch_exceptions
def GetRunLog(self, run_id):
Expand Down
6 changes: 5 additions & 1 deletion wes_service/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def log_for_run(self, run_id, message):
def collect_attachments(self, run_id=None):
tempdir = tempfile.mkdtemp()
body = {}
has_attachments = False
for k, ls in iterlists(connexion.request.files):
for v in ls:
if k == "workflow_attachment":
Expand All @@ -62,6 +63,7 @@ def collect_attachments(self, run_id=None):
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()
Expand All @@ -77,9 +79,11 @@ def collect_attachments(self, run_id=None):

if "workflow_url" in body:
if ":" not in body["workflow_url"]:
if not has_attachments:
raise ValueError("Relative 'workflow_url' but missing 'workflow_attachment'")
body["workflow_url"] = "file://%s" % os.path.join(tempdir, secure_filename(body["workflow_url"]))
self.log_for_run(run_id, "Using workflow_url '%s'" % body.get("workflow_url"))
else:
raise Exception("Missing 'workflow_url' in submission")
raise ValueError("Missing 'workflow_url' in submission")

return tempdir, body

0 comments on commit 4c03521

Please sign in to comment.