Skip to content

Commit 8680ebc

Browse files
authored
Merge pull request #1180 from ReactionMechanismGenerator/PreventInfiniteLoop
Added a raise DatabaseError to thermo.py
2 parents 6c8976f + a408978 commit 8680ebc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

rmgpy/data/thermo.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,13 +1738,23 @@ def __addGroupThermoData(self, thermoData, database, molecule, atom):
17381738
if node is None:
17391739
raise DatabaseError('Unable to determine thermo parameters for {0}: no data for node {1} or any of its ancestors.'.format(molecule, node0) )
17401740

1741-
data = node.data; comment = node.label
1742-
while isinstance(data, basestring) and data is not None:
1743-
for entry in database.entries.values():
1741+
data = node.data
1742+
comment = node.label
1743+
loop_count = 0
1744+
while isinstance(data, basestring):
1745+
loop_count += 1
1746+
if loop_count > 100:
1747+
raise DatabaseError("Maximum iterations reached while following thermo group data pointers. A circular"
1748+
" reference may exist. Last node was {0} pointing to group called {1} in "
1749+
"database {2}".format(node.label, data, database.label))
1750+
1751+
for entry in database.entries.itervalues():
17441752
if entry.label == data:
17451753
data = entry.data
17461754
comment = entry.label
17471755
break
1756+
else:
1757+
raise DatabaseError("Node {0} points to a non-existant group called {1} in database: {2}".format(node.label, data, database.label))
17481758
data.comment = '{0}({1})'.format(database.label, comment)
17491759

17501760
# This code prints the hierarchy of the found node; useful for debugging

0 commit comments

Comments
 (0)