GCodeProfileReader: make deserialization more robust

CURA-3770
This commit is contained in:
Lipu Fei 2017-05-08 11:33:14 +02:00
parent 3a5a28cc38
commit a3d92d557d

View File

@ -56,7 +56,7 @@ class GCodeProfileReader(ProfileReader):
# TODO: Consider moving settings to the start?
serialized = "" # Will be filled with the serialized profile.
try:
with open(file_name) as f:
with open(file_name, "r") as f:
for line in f:
if line.startswith(prefix):
# Remove the prefix and the newline from the line and add it to the rest.
@ -66,9 +66,13 @@ class GCodeProfileReader(ProfileReader):
return None
serialized = unescapeGcodeComment(serialized)
Logger.log("i", "Serialized the following from %s: %s" %(file_name, repr(serialized)))
json_data = json.loads(serialized)
# serialized data can be invalid JSON
try:
json_data = json.loads(serialized)
except Exception as e:
Logger.log("e", "Could not parse serialized JSON data from GCode %s, error: %s", file_name, e)
return None
profiles = []
global_profile = readQualityProfileFromString(json_data["global_quality"])