Handle errors is toolbit json more gracefully

This commit is contained in:
sliptonic
2020-11-14 11:06:02 -06:00
parent cbc8524ff9
commit dbf3ebeabe
2 changed files with 14 additions and 8 deletions

View File

@@ -367,6 +367,7 @@ class ToolBit(object):
def Declaration(path):
PathLog.track(path)
with open(path, 'r') as fp:
return json.load(fp)

View File

@@ -140,14 +140,19 @@ class ModelFactory(object):
library = json.load(fp)
for toolBit in library['tools']:
nr = toolBit['nr']
bit = PathToolBit.findBit(toolBit['path'])
if bit:
PathLog.track(bit)
tool = PathToolBit.Declaration(bit)
datamodel.appendRow(self._toolAdd(nr, tool, bit))
else:
PathLog.error("Could not find tool #{}: {}".format(nr, toolBit['path']))
try:
nr = toolBit['nr']
bit = PathToolBit.findBit(toolBit['path'])
if bit:
PathLog.track(bit)
tool = PathToolBit.Declaration(bit)
datamodel.appendRow(self._toolAdd(nr, tool, bit))
else:
PathLog.error("Could not find tool #{}: {}".format(nr, toolBit['path']))
except Exception as e:
msg = "Error loading tool: {} : {}".format(toolBit['path'], e)
FreeCAD.Console.PrintError(msg)
def _toolAdd(self, nr, tool, path):