Don't crash when reading corrupt 3MF files

Otherwise it would crash with a BadZipFile error. We should be robust against that. This will trigger a generic message that we couldn't read that file to the user, and put more information in the log.

Fixes Sentry issue CURA-NH.
This commit is contained in:
Ghostkeeper 2020-04-29 14:03:50 +02:00
parent dcac9b6a87
commit abffb6c26c
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -738,11 +738,15 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
@staticmethod @staticmethod
def _loadMetadata(file_name: str) -> Dict[str, Dict[str, Any]]: def _loadMetadata(file_name: str) -> Dict[str, Dict[str, Any]]:
archive = zipfile.ZipFile(file_name, "r") result = dict()
try:
archive = zipfile.ZipFile(file_name, "r")
except zipfile.BadZipFile:
Logger.logException("w", "Unable to retrieve metadata from {fname}: 3MF archive is corrupt.".format(fname = file_name))
return result
metadata_files = [name for name in archive.namelist() if name.endswith("plugin_metadata.json")] metadata_files = [name for name in archive.namelist() if name.endswith("plugin_metadata.json")]
result = dict()
for metadata_file in metadata_files: for metadata_file in metadata_files:
try: try: