Catch ContainerFormatError when deserialising containers

Only the deserialize() functions themselves may pass the ContainerFormatError on, because their callers will have to handle those errors anyway.

Contributes to issue CURA-5045.
This commit is contained in:
Ghostkeeper 2018-04-06 13:26:16 +02:00
parent c9dc429b2b
commit 572721e20d
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A
6 changed files with 48 additions and 23 deletions

View file

@ -1,4 +1,4 @@
# Copyright (c) 2017 Ultimaker B.V.
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import os.path
@ -22,12 +22,10 @@ from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.InstanceContainer import InstanceContainer
from UM.MimeTypeDatabase import MimeTypeNotFoundError
from UM.Settings.ContainerFormatError import ContainerFormatError
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.i18n import i18nCatalog
from cura.Settings.ExtruderManager import ExtruderManager
from cura.Settings.ExtruderStack import ExtruderStack
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
@ -289,7 +287,9 @@ class ContainerManager(QObject):
with open(file_url, "rt", encoding = "utf-8") as f:
container.deserialize(f.read())
except PermissionError:
return {"status": "error", "message": "Permission denied when trying to read the file"}
return {"status": "error", "message": "Permission denied when trying to read the file."}
except ContainerFormatError:
return {"status": "error", "Message": "The material file appears to be corrupt."}
except Exception as ex:
return {"status": "error", "message": str(ex)}