Skip to content

Commit

Permalink
Tweaking error messages when seeking nodes in thermo trees.
Browse files Browse the repository at this point in the history
Trying to add a little more detail, and switching to f-strings
  • Loading branch information
rwest committed Oct 23, 2020
1 parent 4d239a5 commit 8948f18
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions rmgpy/data/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ def _add_group_thermo_data(self, thermo_data, database, molecule, atom):
"""
node0 = database.descend_tree(molecule, atom, None)
if node0 is None:
raise KeyError('Node not found in thermo database for atom {0} in molecule {1}.'.format(atom, molecule))
raise KeyError(f'Node not found for atom {atom} in molecule {molecule} in thermo database {database.label}.')

# It's possible (and allowed) that items in the tree may not be in the
# library, in which case we need to fall up the tree until we find an
Expand All @@ -2413,8 +2413,8 @@ def _add_group_thermo_data(self, thermo_data, database, molecule, atom):
while node is not None and node.data is None:
node = node.parent
if node is None:
raise DatabaseError('Unable to determine thermo parameters for {0}: no data for node {1} or '
'any of its ancestors.'.format(molecule, node0))
raise DatabaseError(f'Unable to determine thermo parameters for atom {atom} in molecule {molecule}: '
f'no data for node {node0} or any of its ancestors in database {database.label}.')

data = node.data
comment = node.label
Expand All @@ -2423,18 +2423,18 @@ def _add_group_thermo_data(self, thermo_data, database, molecule, atom):
loop_count += 1
if loop_count > 100:
raise DatabaseError("Maximum iterations reached while following thermo group data pointers. A circular"
" reference may exist. Last node was {0} pointing to group called {1} in "
"database {2}".format(node.label, data, database.label))
f" reference may exist. Last node was {node.label} pointing to group called {data} in "
f"database {database.label}")

for entry in database.entries.values():
if entry.label == data:
data = entry.data
comment = entry.label
break
else:
raise DatabaseError("Node {0} points to a non-existing group called {1} in database: "
"{2}".format(node.label, data, database.label))
data.comment = '{0}({1})'.format(database.label, comment)
raise DatabaseError(f"Node {node.label} points to a non-existing group called {data} "
f"in database {database.label}")
data.comment = f'{database.label}({comment})'

# This code prints the hierarchy of the found node; useful for debugging
# result = ''
Expand All @@ -2458,7 +2458,7 @@ def _remove_group_thermo_data(self, thermo_data, database, molecule, atom):
"""
node0 = database.descend_tree(molecule, atom, None)
if node0 is None:
raise KeyError('Node not found in database.')
raise KeyError(f'Node not found for atom {atom} in molecule {molecule} in thermo database {database.label}.')

# It's possible (and allowed) that items in the tree may not be in the
# library, in which case we need to fall up the tree until we find an
Expand All @@ -2467,28 +2467,27 @@ def _remove_group_thermo_data(self, thermo_data, database, molecule, atom):
while node.data is None and node is not None:
node = node.parent
if node is None:
raise DatabaseError('Unable to determine thermo parameters for {0}: no data for node {1} or any of'
' its ancestors.'.format(molecule, node0))
raise DatabaseError(f'Unable to determine thermo parameters for atom {atom} in molecule {molecule}: '
f'no data for node {node0} or any of its ancestors in database {database.label}.')

data = node.data
comment = node.label
loop_count = 0
while isinstance(data, str):
loop_count += 1
if loop_count > 100:
raise DatabaseError(
"Maximum iterations reached while following thermo group data pointers. A circular"
" reference may exist. Last node was {0} pointing to group called {1} in"
" database {2}".format(node.label, data, database.label))
raise DatabaseError("Maximum iterations reached while following thermo group data pointers. A circular"
f" reference may exist. Last node was {node.label} pointing to group called {data} in "
f"database {database.label}")
for entry in database.entries.values():
if entry.label == data:
data = entry.data
comment = entry.label
break
else:
raise DatabaseError("Node {0} points to a non-existant group called {1} in database: "
"{2}".format(node.label, data, database.label))
data.comment = '{0}({1})'.format(database.label, comment)
raise DatabaseError(f"Node {node.label} points to a non-existing group called {data} "
f"in database {database.label}")
data.comment = f'{database.label}({comment})'

# This code prints the hierarchy of the found node; useful for debugging
# result = ''
Expand Down

0 comments on commit 8948f18

Please sign in to comment.