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.
This commit is contained in:
Ghostkeeper 2020-04-14 18:37:22 +02:00
parent ea2eb2ce41
commit 4050d3ccde
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -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. # Cura is released under the terms of the LGPLv3 or higher.
import os import os
@ -7,6 +7,7 @@ from collections import OrderedDict
from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtCore import pyqtSlot, Qt
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.Settings.SettingFunction import SettingFunction 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. # Find the category of the instance by moving up until we find a category.
category = user_changes.getInstance(setting_key).definition category = user_changes.getInstance(setting_key).definition
while category.type != "category": while category is not None and category.type != "category":
category = category.parent category = category.parent
# Handle translation (and fallback if we weren't able to find any translation files. # Handle translation (and fallback if we weren't able to find any translation files.
if category is not None:
if self._i18n_catalog: if self._i18n_catalog:
category_label = self._i18n_catalog.i18nc(category.key + " label", category.label) category_label = self._i18n_catalog.i18nc(category.key + " label", category.label)
else: else:
category_label = category.label 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: if self._i18n_catalog:
label = self._i18n_catalog.i18nc(setting_key + " label", stack.getProperty(setting_key, "label")) label = self._i18n_catalog.i18nc(setting_key + " label", stack.getProperty(setting_key, "label"))