From 4050d3ccde1295ee5ce429638afe849a32381296 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 14 Apr 2020 18:37:22 +0200 Subject: [PATCH] Prevent crash when a setting is not in any setting category I don't know what exactly caused this since it's impossible to trace. But the crash happened with a setting called 'dual_gcode' which currently doesn't exist in Cura. So I think it must be some plug-in that adds it. In any case, it's good to be defensive about this sort of thing. Good type checking would've caught this for us. Fixes Sentry issue CURA-JB. --- cura/Machines/Models/UserChangesModel.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cura/Machines/Models/UserChangesModel.py b/cura/Machines/Models/UserChangesModel.py index ec623f0f38..43bbe8a663 100644 --- a/cura/Machines/Models/UserChangesModel.py +++ b/cura/Machines/Models/UserChangesModel.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import os @@ -7,6 +7,7 @@ from collections import OrderedDict from PyQt5.QtCore import pyqtSlot, Qt from UM.Application import Application +from UM.Logger import Logger from UM.Settings.ContainerRegistry import ContainerRegistry from UM.i18n import i18nCatalog from UM.Settings.SettingFunction import SettingFunction @@ -83,14 +84,18 @@ class UserChangesModel(ListModel): # Find the category of the instance by moving up until we find a category. category = user_changes.getInstance(setting_key).definition - while category.type != "category": + while category is not None and category.type != "category": category = category.parent # Handle translation (and fallback if we weren't able to find any translation files. - if self._i18n_catalog: - category_label = self._i18n_catalog.i18nc(category.key + " label", category.label) - else: - category_label = category.label + if category is not None: + if self._i18n_catalog: + category_label = self._i18n_catalog.i18nc(category.key + " label", category.label) + else: + category_label = category.label + else: # Setting is not in any category. Shouldn't happen, but it do. See https://sentry.io/share/issue/d735884370154166bc846904d9b812ff/ + Logger.error("Setting {key} is not in any setting category.".format(key = setting_key)) + category_label = "" if self._i18n_catalog: label = self._i18n_catalog.i18nc(setting_key + " label", stack.getProperty(setting_key, "label"))