Skip to content

Commit

Permalink
Merge pull request #2661 from rwest/debugdatabase
Browse files Browse the repository at this point in the history
Better debugging messages for database errors.
  • Loading branch information
JacksonBurns committed May 17, 2024
2 parents 6a5ebf4 + 55bfc65 commit d426379
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions rmgpy/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,17 @@ def load(self, path, local_context=None, global_context=None):
local_context[key] = value

# Process the file
f = open(path, 'r')
with open(path, 'r') as f:
content = f.read()
try:
exec(f.read(), global_context, local_context)
except Exception:
logging.error('Error while reading database {0!r}.'.format(path))
exec(content, global_context, local_context)
except Exception as e:
logging.exception(f'Error while reading database file {path}.')
line_number = e.__traceback__.tb_next.tb_lineno
logging.error(f'Error occurred at or near line {line_number} of {path}.')
lines = content.splitlines()
logging.error(f'Line: {lines[line_number - 1]}')
raise
f.close()

# Extract the database metadata
self.name = local_context['name']
Expand Down

0 comments on commit d426379

Please sign in to comment.