Don't crash when importing definition files as materials

Reproduction steps:
* In the Material Manager, click on 'Import material'.
* Change the file type in the file dialogue to 'All files'.
* Select any .def.json file, for example from Cura's own resources/definitions folder.

Previously this crashed the application. Now it shows the user an error message instead.

Fixes Sentry error CURA-D4.
This commit is contained in:
Ghostkeeper 2020-03-23 09:06:20 +01:00
parent 485e37e7f5
commit 566af8be2e
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -239,6 +239,8 @@ class ContainerManager(QObject):
container_type = container_registry.getContainerForMimeType(mime_type)
if not container_type:
return {"status": "error", "message": "Could not find a container to handle the specified file."}
if not issubclass(container_type, InstanceContainer):
return {"status": "error", "message": "This is not a material container, but another type of file."}
container_id = urllib.parse.unquote_plus(mime_type.stripExtension(os.path.basename(file_url)))
container_id = container_registry.uniqueName(container_id)