Skip to content

Commit b4fd590

Browse files
committed
Better error message when parsing hints
Removed unnecessary checks for reqs/steps; the schema loader catches those
1 parent 0fb96db commit b4fd590

File tree

4 files changed

+117
-14
lines changed

4 files changed

+117
-14
lines changed

cwltool/update.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,26 @@ def v1_0to1_1(
5555
def rewrite_requirements(t: CWLObjectType) -> None:
5656
if "requirements" in t:
5757
for r in cast(MutableSequence[CWLObjectType], t["requirements"]):
58-
if isinstance(r, MutableMapping):
59-
cls = cast(str, r["class"])
60-
if cls in rewrite:
61-
r["class"] = rewrite[cls]
62-
else:
63-
raise ValidationException(
64-
"requirements entries must be dictionaries: {} {}.".format(type(r), r)
65-
)
58+
cls = cast(str, r["class"])
59+
if cls in rewrite:
60+
r["class"] = rewrite[cls]
6661
if "hints" in t:
67-
for r in cast(MutableSequence[CWLObjectType], t["hints"]):
62+
for index, r in enumerate(cast(MutableSequence[CWLObjectType], t["hints"])):
6863
if isinstance(r, MutableMapping):
64+
if "class" not in r:
65+
raise SourceLine(r, None, ValidationException).makeError(
66+
"'hints' entry missing required key 'class'."
67+
)
6968
cls = cast(str, r["class"])
7069
if cls in rewrite:
7170
r["class"] = rewrite[cls]
7271
else:
73-
raise ValidationException(f"hints entries must be dictionaries: {type(r)} {r}.")
72+
raise SourceLine(t["hints"], index, ValidationException).makeError(
73+
f"'hints' entries must be dictionaries: {type(r)} {r}."
74+
)
7475
if "steps" in t:
7576
for s in cast(MutableSequence[CWLObjectType], t["steps"]):
76-
if isinstance(s, MutableMapping):
77-
rewrite_requirements(s)
78-
else:
79-
raise ValidationException(f"steps entries must be dictionaries: {type(s)} {s}.")
77+
rewrite_requirements(s)
8078

8179
def update_secondaryFiles(
8280
t: CWLOutputType, top: bool = False

tests/test_load_tool.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55
import pytest
6+
from schema_salad.exceptions import ValidationException
67

78
from cwltool.context import LoadingContext, RuntimeContext
89
from cwltool.errors import WorkflowException
@@ -143,3 +144,25 @@ def test_import_tracked() -> None:
143144

144145
assert tool.doc_loader is not None
145146
assert path in tool.doc_loader.idx
147+
148+
149+
def test_load_badhints() -> None:
150+
"""Check for expected error while update a bads hints list."""
151+
loadingContext = LoadingContext()
152+
uri = Path(get_data("tests/wf/hello-workflow-badhints.cwl")).as_uri()
153+
with pytest.raises(
154+
ValidationException,
155+
match=r".*tests\/wf\/hello-workflow-badhints\.cwl\:18:4:\s*'hints'\s*entry\s*missing\s*required\s*key\s*'class'\.",
156+
):
157+
load_tool(uri, loadingContext)
158+
159+
160+
def test_load_badhints_nodict() -> None:
161+
"""Check for expected error while update a hints list with a numerical entry."""
162+
loadingContext = LoadingContext()
163+
uri = Path(get_data("tests/wf/hello-workflow-badhints2.cwl")).as_uri()
164+
with pytest.raises(
165+
ValidationException,
166+
match=r".*tests\/wf\/hello-workflow-badhints2\.cwl:41:5:\s*'hints'\s*entries\s*must\s*be\s*dictionaries:\s*<class\s*'int'>\s*42\.",
167+
):
168+
load_tool(uri, loadingContext)

tests/wf/hello-workflow-badhints.cwl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.0
4+
class: Workflow
5+
6+
label: "Hello World"
7+
doc: "Outputs a message using echo"
8+
9+
inputs:
10+
usermessage: string
11+
12+
outputs:
13+
response:
14+
outputSource: step0/response
15+
type: File
16+
17+
hints:
18+
- {}
19+
20+
steps:
21+
step0:
22+
run:
23+
class: CommandLineTool
24+
inputs:
25+
message:
26+
type: string
27+
doc: "The message to print"
28+
default: "Hello World"
29+
inputBinding:
30+
position: 1
31+
baseCommand: echo
32+
arguments:
33+
- "-n"
34+
- "-e"
35+
stdout: response.txt
36+
outputs:
37+
response:
38+
type: stdout
39+
in:
40+
message: usermessage
41+
out: [response]

tests/wf/hello-workflow-badhints2.cwl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
cwlVersion: v1.0
4+
class: Workflow
5+
6+
label: "Hello World"
7+
doc: "Outputs a message using echo"
8+
9+
inputs:
10+
usermessage: string
11+
12+
outputs:
13+
response:
14+
outputSource: step0/response
15+
type: File
16+
17+
steps:
18+
step0:
19+
run:
20+
class: CommandLineTool
21+
inputs:
22+
message:
23+
type: string
24+
doc: "The message to print"
25+
default: "Hello World"
26+
inputBinding:
27+
position: 1
28+
baseCommand: echo
29+
arguments:
30+
- "-n"
31+
- "-e"
32+
stdout: response.txt
33+
outputs:
34+
response:
35+
type: stdout
36+
in:
37+
message: usermessage
38+
out: [response]
39+
40+
hints:
41+
- 42

0 commit comments

Comments
 (0)