From c973b3493c19a8a784806cc78157a33a67ae9bd9 Mon Sep 17 00:00:00 2001 From: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Date: Thu, 8 Sep 2022 13:31:08 -0700 Subject: [PATCH] Check all files and accumulate all errors before raising any exceptions. --- .../modules/github_service.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/docker_detection_tester/modules/github_service.py b/bin/docker_detection_tester/modules/github_service.py index 7d60abf51d..54085bf137 100644 --- a/bin/docker_detection_tester/modules/github_service.py +++ b/bin/docker_detection_tester/modules/github_service.py @@ -164,10 +164,22 @@ class GithubService: #We are down to just the detections we care about #Parse and load each of them, which will ensure that they pass their validations import modules.test_driver - detection_objects = [modules.test_driver.Detection(d) for d in detections] + detection_objects = [] + errors = [] + for detection in detections: + try: + detection_objects.append(modules.test_driver.Detection(detection)) + except Exception as e: + errors.append(f"Error parsing detection {detection}: {str(e)}") + + if len(errors) != 0: + all_errors_string = '\n\t'.join(errors) + raise Exception(f"The following errors were encountered while parsing detections:\n\t{all_errors_string}") + print(f"Detection objects that were parsed: {len(detection_objects)}") + detection_objects = [d for d in detection_objects if d.detectionFile.type in allowed_types] print(f"Detection objects after downselecting to {allowed_types}: {len(detection_objects)}")