Skip to content

Commit b9503bf

Browse files
author
Peter Amstutz
committed
Improve error reporting for bad requests
1 parent 207b971 commit b9503bf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

wes_service/arvados_wes.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def RunWorkflow(self, **args):
197197
"output_path": "n/a",
198198
"priority": 500}}).execute()
199199

200+
success = False
200201
try:
201202
tempdir, body = self.collect_attachments(cr["uuid"])
202203

@@ -210,14 +211,22 @@ def RunWorkflow(self, **args):
210211
env,
211212
project_uuid,
212213
tempdir)).start()
213-
214+
success = True
215+
except ValueError as e:
216+
self.log_for_run(cr["uuid"], "Bad request: " + str(e))
217+
cr = api.container_requests().update(uuid=cr["uuid"],
218+
body={"container_request":
219+
{"priority": 0}}).execute()
220+
return {"msg": str(e), "status_code": 400}, 400
214221
except Exception as e:
215222
logging.exception("Error")
216223
self.log_for_run(cr["uuid"], "An exception ocurred while handling your request: " + str(e))
217224
cr = api.container_requests().update(uuid=cr["uuid"],
218225
body={"container_request":
219226
{"priority": 0}}).execute()
220-
return {"run_id": cr["uuid"]}
227+
return {"msg": str(e), "status_code": 500}, 500
228+
else:
229+
return {"run_id": cr["uuid"]}
221230

222231
@catch_exceptions
223232
def GetRunLog(self, run_id):

wes_service/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def log_for_run(self, run_id, message):
4949
def collect_attachments(self, run_id=None):
5050
tempdir = tempfile.mkdtemp()
5151
body = {}
52+
has_attachments = False
5253
for k, ls in iterlists(connexion.request.files):
5354
for v in ls:
5455
if k == "workflow_attachment":
@@ -62,7 +63,7 @@ def collect_attachments(self, run_id=None):
6263
os.makedirs(os.path.dirname(dest))
6364
self.log_for_run(run_id, "Staging attachment '%s' to '%s'" % (v.filename, dest))
6465
v.save(dest)
65-
body[k] = "file://%s" % tempdir # Reference to temp working dir.
66+
has_attachments = True
6667
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
6768
content = v.read()
6869
body[k] = json.loads(content.decode("utf-8"))
@@ -77,9 +78,11 @@ def collect_attachments(self, run_id=None):
7778

7879
if "workflow_url" in body:
7980
if ":" not in body["workflow_url"]:
81+
if not has_attachments:
82+
raise ValueError("Relative 'workflow_url' but missing 'workflow_attachment'")
8083
body["workflow_url"] = "file://%s" % os.path.join(tempdir, secure_filename(body["workflow_url"]))
8184
self.log_for_run(run_id, "Using workflow_url '%s'" % body.get("workflow_url"))
8285
else:
83-
raise Exception("Missing 'workflow_url' in submission")
86+
raise ValueError("Missing 'workflow_url' in submission")
8487

8588
return tempdir, body

0 commit comments

Comments
 (0)