From a7468da59b0b8f9d0c751673892e753920dea463 Mon Sep 17 00:00:00 2001 From: Piotr Zaborowski Date: Thu, 15 Jun 2023 00:32:43 +0200 Subject: [PATCH] Add better error handing for malformed .yaml files --- scripts/tag_autocomplete_helper.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/tag_autocomplete_helper.py b/scripts/tag_autocomplete_helper.py index 9e47af9..301b0e3 100644 --- a/scripts/tag_autocomplete_helper.py +++ b/scripts/tag_autocomplete_helper.py @@ -86,14 +86,18 @@ def get_ext_wildcard_tags(): try: with open(path, encoding="utf8") as file: data = yaml.safe_load(file) - for item in data: - if data[item] and 'Tags' in data[item]: - wildcard_tags[count] = ','.join(data[item]['Tags']) - count += 1 - else: - print('Issue with tags found in ' + path.name + ' at item ' + item) - except yaml.YAMLError as exc: - print(exc) + if data: + for item in data: + if data[item] and 'Tags' in data[item] and isinstance(data[item]['Tags'], list): + wildcard_tags[count] = ','.join(data[item]['Tags']) + count += 1 + else: + print('Issue with tags found in ' + path.name + ' at item ' + item) + else: + print('No data found in ' + path.name) + except yaml.YAMLError: + print('Issue in parsing YAML file ' + path.name ) + continue # Sort by count sorted_tags = sorted(wildcard_tags.items(), key=lambda item: item[1], reverse=True) output = []