mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
GCodeProfileReader: make deserialization more robust
CURA-3770
This commit is contained in:
parent
3a5a28cc38
commit
a3d92d557d
1 changed files with 7 additions and 3 deletions
|
@ -56,7 +56,7 @@ class GCodeProfileReader(ProfileReader):
|
||||||
# TODO: Consider moving settings to the start?
|
# TODO: Consider moving settings to the start?
|
||||||
serialized = "" # Will be filled with the serialized profile.
|
serialized = "" # Will be filled with the serialized profile.
|
||||||
try:
|
try:
|
||||||
with open(file_name) as f:
|
with open(file_name, "r") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.startswith(prefix):
|
if line.startswith(prefix):
|
||||||
# Remove the prefix and the newline from the line and add it to the rest.
|
# Remove the prefix and the newline from the line and add it to the rest.
|
||||||
|
@ -66,9 +66,13 @@ class GCodeProfileReader(ProfileReader):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
serialized = unescapeGcodeComment(serialized)
|
serialized = unescapeGcodeComment(serialized)
|
||||||
Logger.log("i", "Serialized the following from %s: %s" %(file_name, repr(serialized)))
|
|
||||||
|
|
||||||
|
# serialized data can be invalid JSON
|
||||||
|
try:
|
||||||
json_data = json.loads(serialized)
|
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 = []
|
profiles = []
|
||||||
global_profile = readQualityProfileFromString(json_data["global_quality"])
|
global_profile = readQualityProfileFromString(json_data["global_quality"])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue