Skip to content

Commit

Permalink
fixes for common JSON errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeZ123 committed Dec 4, 2024
1 parent d3d7d58 commit b6a611f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/common/src/major2-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ function validateSectionRequirement(
tracker: CourseValidationTracker
): Result<Array<Solution>, MajorValidationError> {
if (r.minRequirementCount < 1) {
return Ok([]);
// this should be an invalid shape and throw an error, but for now we'll just return an empty array
// since the solution for a section with no requirements is an empty array
throw new Error("Section requirement count must be >= 1");
}

Expand Down Expand Up @@ -732,5 +735,25 @@ function validateRequirements(
rs: Requirement2[],
tracker: CourseValidationTracker
) {
while (rs.some((r) => Array.isArray(r))) {
const newRs = [];
for (const r of rs) {
if (Array.isArray(r)) {
newRs.push(...extractRequirements(r));
} else {
newRs.push(r);
}
}
rs = newRs;
}

return rs.map((r) => validateRequirement(r, tracker));
}

const extractRequirements = (requirements: Requirement2[]): Requirement2[] => {
const extracted: Requirement2[] = [];
for (const value of requirements) {
extracted.push(value);
}
return extracted;
};

0 comments on commit b6a611f

Please sign in to comment.