Browse Source

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.
Ghostkeeper 4 years ago
parent
commit
4372099e1d
1 changed files with 5 additions and 1 deletions
  1. 5 1
      cura/UI/PrintInformation.py

+ 5 - 1
cura/UI/PrintInformation.py

@@ -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):