diff --git a/processing/load_languages.py b/processing/load_languages.py index 5ee4308..240129e 100644 --- a/processing/load_languages.py +++ b/processing/load_languages.py @@ -92,7 +92,12 @@ def get_acron_issueid_fname_without_extension(file_path): """ _file_path = os.path.normpath(file_path.replace('\\', '/')).lower() try: - file_id = FILE_REGEX.search(_file_path).group() + match = FILE_REGEX.search(_file_path) + if not match: + logger.error( + u'Fail to parse file_path %s: no regex match', file_path) + return + file_id = match.group() file_id, ext = os.path.splitext(file_id) folders = file_id.split('/') if not ext == '.xml': @@ -102,11 +107,11 @@ def get_acron_issueid_fname_without_extension(file_path): folders = folders[-3:] if len(folders) != 3: logger.error( - u'Fail to parse file_path %s for %s', (file_path, file_id)) + u'Fail to parse file_path %s for %s', file_path, file_id) return - except: + except Exception: logger.error( - u'Fail to parse file_path %s for %s', (file_path, file_id)) + u'Fail to parse file_path %s', file_path) return return folders diff --git a/tests/test_load_languages.py b/tests/test_load_languages.py index c64a8de..45605dc 100644 --- a/tests/test_load_languages.py +++ b/tests/test_load_languages.py @@ -80,6 +80,15 @@ def test_get_acron_issueid_fname_without_extension(self): ['mioc', 'v82s3', 'vol82(fsup3)_ii'] ) + def test_get_acron_issueid_fname_without_extension_no_match(self): + get_file_id = load_languages.get_acron_issueid_fname_without_extension + self.assertIsNone( + get_file_id('./argos/aceeed/n21/2545-8299-ACEEED-21-137') + ) + self.assertIsNone( + get_file_id('some/random/path/without/valid/extension') + ) + @patch.object( load_languages.StaticCatalog, "__init__", mock_static_catalog_init_method )