Skip to content

Commit

Permalink
feat(task): adds collection of validation errors in rules task
Browse files Browse the repository at this point in the history
Updates the rules transform task to make sure all errors for a
component defintion are collection during transformation and presented
back to the user to make errors easier to address at one time.

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Oct 11, 2023
1 parent d9ed863 commit 480e523
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion trestlebot/tasks/rule_transform_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def _transform_components(self, component_definition_path: pathlib.Path) -> None
logger.debug(
f"Transforming rules for component definition {component_definition_path.name}"
)

# To report all rule errors at once, we collect them in a list and
# pretty print them in a raised exception
transformation_errors: List[str] = []
for component in self.iterate_models(component_definition_path):
for rule_path in self.iterate_models(component):
# Load the rule into memory as a stream to process
Expand All @@ -102,10 +106,16 @@ def _transform_components(self, component_definition_path: pathlib.Path) -> None
rule = self._rule_transformer.transform(rule_stream)
csv_builder.add_row(rule)
except RulesTransformerException as e:
raise TaskException(
transformation_errors.append(
f"Failed to transform rule {rule_path.name}: {e}"
)

if len(transformation_errors) > 0:
raise TaskException(
f"Failed to transform rules for component definition {component_definition_path.name}: \
\n{', '.join(transformation_errors)}"
)

if csv_builder.row_count == 0:
raise TaskException(
f"No rules found for component definition {component_definition_path.name}"
Expand Down

0 comments on commit 480e523

Please sign in to comment.