Skip to content

Commit

Permalink
Merge pull request #168 from NASA-IMPACT/fixes/misc
Browse files Browse the repository at this point in the history
Add exception handling + fix minor bugs
  • Loading branch information
xhagrg authored Mar 3, 2022
2 parents b370db3 + 1e4c926 commit 3fefe7c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v1.1.4

- Added error handling for errored checks
- Fixed minor bugs

## v1.1.3

- Fixed null pointer exception in the check `collection_progress_consistency_check`
Expand Down
20 changes: 12 additions & 8 deletions pyQuARC/code/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,18 @@ def perform_custom_checks(self, metadata_content):
ordered_rule = self.scheduler.order_rules()
result_dict = {}
for rule_id in ordered_rule:
rule_mapping = self.rules_override.get(
rule_id
) or self.rule_mapping.get(rule_id)
check_id = rule_mapping.get("check_id", rule_id)
check = self.checks_override.get(check_id) or self.checks.get(check_id)
func = Checker.map_to_function(check["data_type"], check["check_function"])
if func:
self._run_func(func, check, rule_id, metadata_content, result_dict)
try:
rule_mapping = self.rules_override.get(
rule_id
) or self.rule_mapping.get(rule_id)
check_id = rule_mapping.get("check_id", rule_id)
check = self.checks_override.get(check_id) or self.checks.get(check_id)
func = Checker.map_to_function(check["data_type"], check["check_function"])
if func:
self._run_func(func, check, rule_id, metadata_content, result_dict)
except Exception as e:
print(f"Running check for the rule: '{rule_id}' failed.\nPlease report the issue to https://github.com/NASA-IMPACT/pyquarc along with the metadata file and the following error message:")
print(f"ERROR: {e}")
return result_dict

def run(self, metadata_content):
Expand Down
4 changes: 3 additions & 1 deletion pyQuARC/code/custom_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def collection_progress_consistency_check(collection_state, ends_at_present_flag
collection_state = collection_state.upper()
ending_date_time_exists = bool(ending_date_time)
ends_at_present_flag_exists = bool(ends_at_present_flag)
ends_at_present_flag = ends_at_present_flag_exists.lower() if ends_at_present_flag_exists else None
ends_at_present_flag = str(ends_at_present_flag).lower() if ends_at_present_flag_exists else None

if collection_state in ["ACTIVE", "IN WORK"]:
validity = (not ending_date_time_exists) and (ends_at_present_flag == "true")
Expand Down Expand Up @@ -197,6 +197,8 @@ def characteristic_name_uniqueness_check(characteristics):
def get_data_url_check(metadata_json):
REQUIRED_TYPE = 'GET DATA'
related_urls = metadata_json.get('Related_URL', [])
if not isinstance(related_urls, list):
related_urls = [related_urls]
validity = False
value = None
for url in related_urls:
Expand Down
2 changes: 1 addition & 1 deletion pyQuARC/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.3
1.1.4

0 comments on commit 3fefe7c

Please sign in to comment.