From 9e1dc98cd139341e7d7963254afa1a31b81a511f Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Oct 2021 14:31:25 +0200 Subject: [PATCH] Catch environment errors when reading license file from package The package may be inaccessible for whatever reason, which would crash Cura. New attempt to fix CURA-2RP (without breaking the unit test saying that this error should be raised by Uranium then). --- plugins/Toolbox/src/CloudSync/LicensePresenter.py | 9 ++++++++- plugins/Toolbox/src/Toolbox.py | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/Toolbox/src/CloudSync/LicensePresenter.py b/plugins/Toolbox/src/CloudSync/LicensePresenter.py index 9a68c93d71..39ce11c8d3 100644 --- a/plugins/Toolbox/src/CloudSync/LicensePresenter.py +++ b/plugins/Toolbox/src/CloudSync/LicensePresenter.py @@ -1,3 +1,6 @@ +# Copyright (c) 2021 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + import os from collections import OrderedDict from typing import Dict, Optional, List, Any @@ -95,7 +98,11 @@ class LicensePresenter(QObject): for package_id, item in packages.items(): item["package_id"] = package_id - item["licence_content"] = self._package_manager.getPackageLicense(item["package_path"]) + try: + item["licence_content"] = self._package_manager.getPackageLicense(item["package_path"]) + except EnvironmentError as e: + Logger.error(f"Could not open downloaded package {package_id} to read license file! {type(e)} - {e}") + continue # Skip this package. if item["licence_content"] is None: # Implicitly accept when there is no license item["accepted"] = True diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 2c06c87047..e525a88d89 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -682,9 +682,13 @@ class Toolbox(QObject, Extension): if not package_info: Logger.log("w", "Package file [%s] was not a valid CuraPackage.", file_path) return - - license_content = self._package_manager.getPackageLicense(file_path) package_id = package_info["package_id"] + + try: + license_content = self._package_manager.getPackageLicense(file_path) + except EnvironmentError as e: + Logger.error(f"Could not open downloaded package {package_id} to read license file! {type(e)} - {e}") + return if license_content is not None: # get the icon url for package_id, make sure the result is a string, never None icon_url = next((x["icon_url"] for x in self.packagesModel.items if x["id"] == package_id), None) or ""