Skip to content

Commit

Permalink
Catch json decode errors and dump the source json data to the log if …
Browse files Browse the repository at this point in the history
…they arise
  • Loading branch information
joepal1976 committed May 14, 2021
1 parent 86bde3e commit 973b5c7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mpfb/entities/material/makeskinmaterial.py
Expand Up @@ -67,7 +67,21 @@ def apply_node_tree(self, blender_material, template_values=None):
for key in template_values:
template_data = template_data.replace("\"$" + key + "\"", template_values[key])

node_tree_dict = json.loads(template_data)
_LOG.dump("Template data", template_data)

node_tree_dict = dict()
parse_error = None

try:
node_tree_dict = json.loads(template_data)
except Exception as exc:
_LOG.error("An error was thrown when trying to parse the template data:", exc)
_LOG.error("Full contents of template data", "\n\n" + str(template_data) + "\n\n")
parse_error = "Failed to parse material: " + str(exc) + ". See material.makeskinmaterial log for more info."

if not parse_error is None:
raise ValueError(parse_error)

_LOG.dump("node_tree", node_tree_dict)

NodeService.apply_node_tree_from_dict(blender_material.node_tree, node_tree_dict, True)
Expand Down

0 comments on commit 973b5c7

Please sign in to comment.