Skip to content

Commit 6e38839

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

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-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: 12 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,14 @@ 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'\sentry\smissing\srequired\skey\s'class'.",
156+
):
157+
load_tool(uri, loadingContext)
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]

0 commit comments

Comments
 (0)