Skip to content

Commit d6abea9

Browse files
author
Alan Christie
committed
fix: Better step validation errors
1 parent 37d4496 commit d6abea9

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

tests/test_workflow_validator_for_run_level.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ def test_validate_duplicate_workflow_variable_names():
149149
)
150150

151151
# Assert
152-
assert error.error_num == 3
152+
assert error.error_num == 6
153153
assert error.error_msg == ["Duplicate workflow variable names found: x"]

tests/test_workflow_validator_for_tag_level.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,5 @@ def test_validate_duplicate_workflow_variable_names():
147147
)
148148

149149
# Assert
150-
assert error.error_num == 3
150+
assert error.error_num == 6
151151
assert error.error_msg == ["Duplicate workflow variable names found: x"]

workflow/workflow_validator.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def _validate_tag_level(
8383
) -> ValidationResult:
8484
assert workflow_definition
8585

86-
# TAG level requires that each step name is unique.
86+
# TAG level requires that each step name is unique,
8787
duplicate_names: set[str] = set()
8888
step_names: set[str] = set()
8989
for step in get_steps(workflow_definition):
90-
step_name = step["name"]
90+
step_name: str = step["name"]
9191
if step_name not in duplicate_names and step_name in step_names:
9292
duplicate_names.add(step_name)
9393
step_names.add(step_name)
@@ -96,6 +96,40 @@ def _validate_tag_level(
9696
error_num=2,
9797
error_msg=[f"Duplicate step names found: {', '.join(duplicate_names)}"],
9898
)
99+
# Each step specification must be a valid JSON string.
100+
# and contain properties for 'collection', 'job', and 'version'.
101+
for step in workflow_definition["steps"]:
102+
step_name = step["name"]
103+
try:
104+
specification = json.loads(step["specification"])
105+
except json.decoder.JSONDecodeError as e:
106+
return ValidationResult(
107+
error_num=3,
108+
error_msg=[
109+
f"Got JSONDecodeError decoding Step '{step_name}' specification: {e}"
110+
],
111+
)
112+
except TypeError as e:
113+
return ValidationResult(
114+
error_num=4,
115+
error_msg=[
116+
f"Got ValidationResult decoding Step '{step_name}' specification: {e}"
117+
],
118+
)
119+
expected_keys: set[str] = {"collection", "job", "version"}
120+
missing_keys: list[str] = []
121+
missing_keys.extend(
122+
expected_key
123+
for expected_key in expected_keys
124+
if expected_key not in specification
125+
)
126+
if missing_keys:
127+
return ValidationResult(
128+
error_num=5,
129+
error_msg=[
130+
f"Step '{step_name}' specification is missing: {', '.join(missing_keys)}"
131+
],
132+
)
99133
# Workflow variables must be unique.
100134
duplicate_names = set()
101135
variable_names: set[str] = set()
@@ -109,7 +143,7 @@ def _validate_tag_level(
109143
variable_names.add(wf_variable_name)
110144
if duplicate_names:
111145
return ValidationResult(
112-
error_num=3,
146+
error_num=6,
113147
error_msg=[
114148
f"Duplicate workflow variable names found: {', '.join(duplicate_names)}"
115149
],
@@ -126,38 +160,6 @@ def _validate_run_level(
126160
) -> ValidationResult:
127161
assert workflow_definition
128162

129-
# RUN level requires that each step specification is a valid JSON string.
130-
# and contains properties for 'collection', 'job', and 'version'.
131-
for step in workflow_definition["steps"]:
132-
try:
133-
specification = json.loads(step["specification"])
134-
except json.decoder.JSONDecodeError as e:
135-
return ValidationResult(
136-
error_num=2,
137-
error_msg=[
138-
f"Error decoding specification, which is not valid JSON: {e}"
139-
],
140-
)
141-
except TypeError as e:
142-
return ValidationResult(
143-
error_num=3,
144-
error_msg=[
145-
f"Error decoding specification, which is not valid JSON: {e}"
146-
],
147-
)
148-
expected_keys: set[str] = {"collection", "job", "version"}
149-
missing_keys: list[str] = []
150-
missing_keys.extend(
151-
expected_key
152-
for expected_key in expected_keys
153-
if expected_key not in specification
154-
)
155-
if missing_keys:
156-
return ValidationResult(
157-
error_num=2,
158-
error_msg=[f"Specification is missing: {', '.join(missing_keys)}"],
159-
)
160-
161163
# We must have values for all the variables defined in the workflow.
162164
wf_variables: list[str] = get_required_variable_names(workflow_definition)
163165
missing_values: list[str] = []
@@ -168,7 +170,7 @@ def _validate_run_level(
168170
)
169171
if missing_values:
170172
return ValidationResult(
171-
error_num=3,
173+
error_num=7,
172174
error_msg=[
173175
f"Missing workflow variable values for: {', '.join(missing_values)}"
174176
],

0 commit comments

Comments
 (0)