Skip to content

Commit cfc0ec7

Browse files
Sambit Kumar Mishrasambit-mishra-NHSD
authored andcommitted
Resolving copilot code smells
1 parent 59734d1 commit cfc0ec7

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/rules_validation_api/validators/iteration_validator.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,21 @@ def validate_rule_cohort_labels_against_iteration_cohorts(self) -> typing.Self:
108108

109109
for label in rule.parsed_cohort_labels:
110110
if label not in allowed_labels:
111-
allowed_str = ", ".join(sorted(allowed_labels))
111+
if allowed_labels:
112+
allowed_str = ", ".join(sorted(allowed_labels))
113+
error_message = (
114+
f"Invalid cohort_label value '{label}'. Allowed values: {allowed_str}."
115+
)
116+
else:
117+
error_message = (
118+
f"Invalid cohort_label value '{label}'. "
119+
"No iteration cohorts are defined, so no cohort labels are allowed."
120+
)
112121
error = InitErrorDetails(
113122
type="value_error",
114123
loc=("iteration_rules", idx, "cohort_label"),
115124
input=rule.cohort_label,
116-
ctx={
117-
"error": f"Invalid cohort_label value '{label}'. Allowed values: {allowed_str}."
118-
},
125+
ctx={"error": error_message},
119126
)
120127
line_errors.append(error)
121128
if line_errors:

0 commit comments

Comments
 (0)