Don't crash if material preferences are corrupt

This time we don't need to catch permission errors and such since we're reading it from a string that was stored in memory (read when the preferences file was read). However we do need to catch JSON Decoding Errors since the JSON syntax might be broken by the user modifying these files or because the file wasn't saved properly before.

Fixes Sentry issue CURA-112.
This commit is contained in:
Ghostkeeper 2020-07-13 11:45:16 +02:00
parent e010d4f945
commit 4372099e1d
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -202,7 +202,11 @@ class PrintInformation(QObject):
self._material_costs[build_plate_number] = []
self._material_names[build_plate_number] = []
material_preference_values = json.loads(self._application.getInstance().getPreferences().getValue("cura/material_settings"))
try:
material_preference_values = json.loads(self._application.getInstance().getPreferences().getValue("cura/material_settings"))
except json.JSONDecodeError:
Logger.warning("Material preference values are corrupt. Will revert to defaults!")
material_preference_values = {}
for index, extruder_stack in enumerate(global_stack.extruderList):
if index >= len(self._material_amounts):