Prevent crashes when a variant could not be found

This should not happen, but we've seen some cases where it would cause a crash, usually
when a previous upgrade did something a bit weird (in this specific case; a printer
with an empty variant, whereas it should have a variant).

Since any change that the user will make will ensure that the variant is no longer empty (eg;
any selection of a variant will mean it's no longer empty) and that there is no way back,
it should be pretty safe to ignore the situation as it will resolve itself eventually

CURA-6992
This commit is contained in:
Jaime van Kessel 2019-11-21 12:54:33 +01:00
parent 9aeb9912c8
commit fb4ce43f0c
No known key found for this signature in database
GPG key ID: 3710727397403C91
2 changed files with 9 additions and 1 deletions

View file

@ -39,7 +39,11 @@ class IntentManager(QObject):
# an empty list if nothing was found.
def intentMetadatas(self, definition_id: str, nozzle_name: str, material_base_file: str) -> List[Dict[str, Any]]:
intent_metadatas = [] # type: List[Dict[str, Any]]
materials = ContainerTree.getInstance().machines[definition_id].variants[nozzle_name].materials
try:
materials = ContainerTree.getInstance().machines[definition_id].variants[nozzle_name].materials
except KeyError:
Logger.log("w", "Unable to find the machine %s or the variant %s", definition_id, nozzle_name)
materials = {}
if material_base_file not in materials:
return intent_metadatas