diff options
author | Lipu Fei <lipu.fei815@gmail.com> | 2017-05-08 12:33:14 +0300 |
---|---|---|
committer | Lipu Fei <lipu.fei815@gmail.com> | 2017-05-08 12:33:50 +0300 |
commit | a3d92d557dc1b3aa9eb9446e6dd819f3d9cece7c (patch) | |
tree | 11b5dc89318ba64783dedbf3cfb1eafabd1038c0 /plugins/GCodeProfileReader | |
parent | 3a5a28cc38f4566911b1e7cb05eac96ac294c19b (diff) |
GCodeProfileReader: make deserialization more robust
CURA-3770
Diffstat (limited to 'plugins/GCodeProfileReader')
-rw-r--r-- | plugins/GCodeProfileReader/GCodeProfileReader.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index abfef6e296..0abbcfc833 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -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"]) |