Skip to content

Commit

Permalink
Add uncaught error to wdl_output.json (#62)
Browse files Browse the repository at this point in the history
* add uncaught error to wdl_output.json

* add test

* lint
  • Loading branch information
rzlim08 authored Apr 22, 2022
1 parent 5bd6204 commit 3cdcf8f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ handle_error() {
if jq -re $EP $OF; then
if tail -n 1 $(jq -r $EP $OF) | jq -re .wdl_error_message; then
tail -n 1 $(jq -r $EP $OF) > $OF;
else
export err_type=UncaughtError err_msg=$(tail -n 1 $(jq -r $EP $OF))
jq -nc ".wdl_error_message=true | .error=env.err_type | .cause=env.err_msg" > $OF;
fi;
fi;
$aws s3 cp $OF "$WDL_OUTPUT_URI";
Expand Down
68 changes: 67 additions & 1 deletion test/test_wdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,48 @@
}
"""

test_fail_wdl = """
version 1.0
workflow swipe_test {
input {
File hello
String docker_image_id
}
call add_world {
input:
hello = hello,
docker_image_id = docker_image_id
}
output {
File out = add_world.out
}
}
task add_world {
input {
File hello
String docker_image_id
}
command <<<
set -euxo pipefail
cat ~{hello} > out.txt
exit 1
echo world >> out.txt
>>>
output {
File out = "out.txt"
}
runtime {
docker: docker_image_id
}
}
"""

test_two_wdl = """
version 1.0
workflow swipe_test_two {
Expand Down Expand Up @@ -105,6 +147,8 @@ def setUp(self) -> None:
self.sqs = boto3.client("sqs", endpoint_url="http://localhost:9000")
self.wdl_obj = self.test_bucket.Object("test-v1.0.0.wdl")
self.wdl_obj.put(Body=test_wdl.encode())
self.wdl_fail_obj = self.test_bucket.Object("test-fail-v1.0.0.wdl")
self.wdl_fail_obj.put(Body=test_fail_wdl.encode())
self.wdl_two_obj = self.test_bucket.Object("test-two-v1.0.0.wdl")
self.wdl_two_obj.put(Body=test_two_wdl.encode())
self.map_obj = self.test_bucket.Object("stage_io_map.json")
Expand Down Expand Up @@ -138,6 +182,7 @@ def _wait_sfn(
sfn_input: Dict,
sfn_arn: str,
n_stages: int = 1,
expect_success: bool = True
) -> Tuple[str, Dict, List[Dict]]:
execution_name = "swipe-test-{}".format(int(time.time()))
res = self.sfn.start_execution(
Expand All @@ -161,7 +206,10 @@ def _wait_sfn(
print(resp)
messages = resp["Messages"]

self.assertEqual(description["status"], "SUCCEEDED", description)
if expect_success:
self.assertEqual(description["status"], "SUCCEEDED", description)
else:
self.assertEqual(description["status"], "FAILED", description)
return arn, description, messages

def test_simple_sfn_wdl_workflow(self):
Expand Down Expand Up @@ -194,6 +242,24 @@ def test_simple_sfn_wdl_workflow(self):
json.loads(messages[0]["Body"])["detail"]["lastCompletedStage"], "run"
)

def test_failing_wdl_workflow(self):
output_prefix = "out-fail-1"
sfn_input: Dict[str, Any] = {
"RUN_WDL_URI": f"s3://{self.wdl_fail_obj.bucket_name}/{self.wdl_fail_obj.key}",
"OutputPrefix": f"s3://{self.input_obj.bucket_name}/{output_prefix}",
"Input": {
"Run": {
"hello": f"s3://{self.input_obj.bucket_name}/{self.input_obj.key}",
"docker_image_id": "ubuntu",
}
},
}

arn, description, messages = self._wait_sfn(sfn_input, self.single_sfn_arn, expect_success=False)
errorType = (self.sfn.get_execution_history(executionArn=arn)["events"]
[-1]["executionFailedEventDetails"]["error"])
self.assertEqual(errorType, "UncaughtError")

def test_staged_sfn_wdl_workflow(self):
output_prefix = "out-2"
sfn_input: Dict[str, Any] = {
Expand Down

0 comments on commit 3cdcf8f

Please sign in to comment.