Addon Manager: Improve error handling for Version

This commit is contained in:
Chris Hennes
2023-05-19 17:17:29 -05:00
parent ba5e7b184d
commit 89d8c57ee8
2 changed files with 24 additions and 28 deletions

View File

@@ -273,7 +273,13 @@ class MetadataReader:
# Text-only elements
metadata.__dict__[tag] = child.text
elif tag in ["version", "freecadmin", "freecadmax", "pythonmin"]:
metadata.__dict__[tag] = Version(from_string=child.text)
try:
metadata.__dict__[tag] = Version(from_string=child.text)
except ValueError:
print(
f"Invalid version specified for tag {tag} in Addon {metadata.name}: {child.text}"
)
metadata.__dict__[tag] = Version(from_list=[0, 0, 0])
elif tag in ["tag", "file"]:
# Lists of strings
if child.text:
@@ -321,9 +327,7 @@ class MetadataReader:
v_gte = child.attrib["version_gte"] if "version_gte" in child.attrib else ""
v_gt = child.attrib["version_gt"] if "version_gt" in child.attrib else ""
condition = child.attrib["condition"] if "condition" in child.attrib else ""
optional = (
"optional" in child.attrib and child.attrib["optional"].lower() == "true"
)
optional = "optional" in child.attrib and child.attrib["optional"].lower() == "true"
dependency_type = DependencyType.automatic
if "type" in child.attrib and child.attrib["type"] in DependencyType.__dict__:
dependency_type = DependencyType[child.attrib["type"]]
@@ -349,17 +353,13 @@ class MetadataReader:
if content_type in known_content_types:
if content_type not in metadata.content:
metadata.content[content_type] = []
metadata.content[content_type].append(
MetadataReader._create_node(namespace, child)
)
metadata.content[content_type].append(MetadataReader._create_node(namespace, child))
@staticmethod
def _create_node(namespace, child) -> Metadata:
new_content_item = Metadata()
for content_child in child:
MetadataReader._parse_child_element(
namespace, content_child, new_content_item
)
MetadataReader._parse_child_element(namespace, content_child, new_content_item)
return new_content_item