Skip to content

Commit

Permalink
[ck2cti] Improve error messages for invalid reaction entries
Browse files Browse the repository at this point in the history
Print the full text of the problematic reaction entry

Print the underlying exception message ahead of the traceback
  • Loading branch information
speth committed Nov 12, 2018
1 parent c1d721d commit 4f4a2bd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions interfaces/cython/cantera/ck2cti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ def readline():
break

lineStartsWithComment = not line and comment
line = line.strip()
line = line.rstrip()
comment = comment.rstrip()

if '=' in line and not lineStartsWithComment:
Expand All @@ -1843,7 +1843,7 @@ def readline():
kinetics = ''
comments = ''

if line:
if line.strip():
kinetics += line + '\n'
if comment:
comments += comment + '\n'
Expand All @@ -1869,7 +1869,9 @@ def readline():
reaction, revReaction = self.readKineticsEntry(kinetics, surface)
except Exception as e:
self.line_number = line_number
logging.info('Error reading reaction entry starting on line {0}:'.format(line_number))
logging.info('Error reading reaction starting on '
'line {0}:\n"""\n{1}\n"""'.format(
line_number, kinetics.rstrip()))
raise
reaction.line_number = line_number
reaction.comment = comment
Expand Down Expand Up @@ -2198,9 +2200,9 @@ def convertMech(inputFile, thermoFile=None, transportFile=None,
try:
# Read input mechanism files
parser.loadChemkinFile(inputFile)
except Exception:
logging.warning("\nERROR: Unable to parse '{0}' near line {1}:\n".format(
inputFile, parser.line_number))
except Exception as err:
logging.warning("\nERROR: Unable to parse '{0}' near line {1}:\n{2}\n".format(
inputFile, parser.line_number, err))
raise
else:
phaseName = None
Expand All @@ -2211,9 +2213,9 @@ def convertMech(inputFile, thermoFile=None, transportFile=None,
try:
# Read input mechanism files
parser.loadChemkinFile(surfaceFile, surface=True)
except Exception:
logging.warning("\nERROR: Unable to parse '{0}' near line {1}:\n".format(
surfaceFile, parser.line_number))
except Exception as err:
logging.warning("\nERROR: Unable to parse '{0}' near line {1}:\n{2}\n".format(
inputFile, parser.line_number, err))
raise

if thermoFile:
Expand Down

0 comments on commit 4f4a2bd

Please sign in to comment.