Skip to content

Commit

Permalink
chore: add error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
breakthewall committed Apr 19, 2023
1 parent 378a249 commit d6566fb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion retropath2_wrapper/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# Errors
'FileNotFound': 1,
'OSError': 2,
'InChI': 3
'InChI': 3,
'SinkFileMalformed': 4,
}
__PACKAGE_FOLDER = os_path.dirname(
os_path.realpath(__file__)
Expand Down
12 changes: 9 additions & 3 deletions retropath2_wrapper/RetroPath2.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def check_input(
return RETCODES['SrcInSink'], None
elif r_code == RETCODES['FileNotFound']:
return RETCODES['FileNotFound'], None
elif r_code == RETCODES['SinkFileMalformed']:
return RETCODES['SinkFileMalformed'], None

return RETCODES['OK'], inchi

Expand Down Expand Up @@ -185,9 +187,13 @@ def check_src_in_sink_1(
try:
with open(sink_file, 'r') as f:
for row in csv_reader(f, delimiter=',', quotechar='"'):
if source_inchi == row[1]:
logger.error(' source has been found in sink')
return RETCODES['SrcInSink']
try:
if source_inchi == row[1]:
logger.error(' source has been found in sink')
return RETCODES['SrcInSink']
except IndexError:
# logger.error(' sink file is not well-formed')
return RETCODES['SinkFileMalformed']

except FileNotFoundError as e:
logger.error(e)
Expand Down
3 changes: 3 additions & 0 deletions retropath2_wrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def _cli():
elif r_code == RETCODES['SrcInSink']:
logger.warning('It seems that the target product is already in the chassis.')
logger.warning('Exiting...')
elif r_code == RETCODES['SinkFileMalformed']:
logger.error('The sink file is malformed.')
logger.error('Exiting...')
else:
logger.error(f'The following error occured: {r_code}')
logger.error('Exiting...')
Expand Down

0 comments on commit d6566fb

Please sign in to comment.