From db09954ac853f261390f8f1f58e0936281057852 Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Wed, 8 Dec 2021 10:59:28 +0100 Subject: [PATCH] Fixed returning an error after the package is destroyed Defensive programming Contributes to: CURA-8587 --- plugins/Marketplace/PackageList.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/Marketplace/PackageList.py b/plugins/Marketplace/PackageList.py index e3af31d81a..f7dcd29feb 100644 --- a/plugins/Marketplace/PackageList.py +++ b/plugins/Marketplace/PackageList.py @@ -237,11 +237,17 @@ class PackageList(ListModel): if reply: reply_string = bytes(reply.readAll()).decode() Logger.error(f"Failed to download package: {package_id} due to {reply_string}") - package = self.getPackageModel(package_id) - if update: - package.is_updating = ManageState.FAILED - else: - package.is_installing = ManageState.FAILED + try: + package = self.getPackageModel(package_id) + if update: + package.is_updating = ManageState.FAILED + else: + package.is_installing = ManageState.FAILED + except RuntimeError: + # Setting the ownership of this object to not qml can still result in a RuntimeError. Which can occur when quickly toggling + # between de-/constructing Remote or Local PackageLists. This try-except is here to prevent a hard crash when the wrapped C++ object + # was deleted when it was still parsing the response + return def subscribeUserToPackage(self, package_id: str, sdk_version: str) -> None: """Subscribe the user (if logged in) to the package for a given SDK