Allow getContainer() to return None

And in the rest of the locations we must then check if it's None and handle that gracefully.
Here we assume that the getContainer message shows a message to the user if necessary. For now we'll just log it.

Contributes to issue CURA-5045.
This commit is contained in:
Ghostkeeper 2018-03-26 15:48:03 +02:00
parent 2a39d81a3c
commit 6d3fed8f52
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A
9 changed files with 52 additions and 23 deletions

View file

@ -30,9 +30,10 @@ class ContainerNode:
def getChildNode(self, child_key: str) -> Optional["ContainerNode"]:
return self.children_map.get(child_key)
def getContainer(self) -> "InstanceContainer":
def getContainer(self) -> Optional["InstanceContainer"]:
if self.metadata is None:
raise RuntimeError("Cannot get container for a ContainerNode without metadata")
Logger.log("e", "Cannot get container for a ContainerNode without metadata.")
return None
if self.container is None:
container_id = self.metadata["id"]
@ -40,7 +41,8 @@ class ContainerNode:
from UM.Settings.ContainerRegistry import ContainerRegistry
container_list = ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
if not container_list:
raise RuntimeError("Failed to lazy-load container [%s], cannot find it" % container_id)
Logger.log("e", "Failed to lazy-load container [{container_id}]. Cannot find it.".format(container_id = container_id))
return None
self.container = container_list[0]
return self.container