From d6566fb7c2db9039c26103df6afdc54a56333007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20H=C3=A9risson?= Date: Thu, 20 Apr 2023 00:29:55 +0200 Subject: [PATCH] chore: add error handler --- retropath2_wrapper/Args.py | 3 ++- retropath2_wrapper/RetroPath2.py | 12 +++++++++--- retropath2_wrapper/__main__.py | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/retropath2_wrapper/Args.py b/retropath2_wrapper/Args.py index 9933e70..e95a549 100644 --- a/retropath2_wrapper/Args.py +++ b/retropath2_wrapper/Args.py @@ -23,7 +23,8 @@ # Errors 'FileNotFound': 1, 'OSError': 2, - 'InChI': 3 + 'InChI': 3, + 'SinkFileMalformed': 4, } __PACKAGE_FOLDER = os_path.dirname( os_path.realpath(__file__) diff --git a/retropath2_wrapper/RetroPath2.py b/retropath2_wrapper/RetroPath2.py index d3a2225..17f47da 100644 --- a/retropath2_wrapper/RetroPath2.py +++ b/retropath2_wrapper/RetroPath2.py @@ -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 @@ -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) diff --git a/retropath2_wrapper/__main__.py b/retropath2_wrapper/__main__.py index 665ff6c..9ad217c 100644 --- a/retropath2_wrapper/__main__.py +++ b/retropath2_wrapper/__main__.py @@ -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...')