Skip to content
Snippets Groups Projects
Commit 444f9831 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

MAINT: Reduce code duplication in error handling

parent e5d75eb6
No related branches found
No related tags found
2 merge requests!217TST: Make NamedTemporaryFiles Windows-compatible,!208ENH: Allow crawler_main to operate on a list of paths
Pipeline #58635 passed
...@@ -1115,42 +1115,28 @@ def crawler_main(crawled_directory_path: str, ...@@ -1115,42 +1115,28 @@ def crawler_main(crawled_directory_path: str,
crawler.run_id) crawler.run_id)
_update_status_record(crawler.run_id, len(inserts), len(updates), status="OK") _update_status_record(crawler.run_id, len(inserts), len(updates), status="OK")
return 0 return 0
except ForbiddenTransaction as err:
logger.debug(traceback.format_exc())
logger.error(err)
_update_status_record(crawler.run_id, 0, 0, status="FAILED")
return 1
except ConverterValidationError as err:
logger.debug(traceback.format_exc())
logger.error(err)
_update_status_record(crawler.run_id, 0, 0, status="FAILED")
return 1
except ImpossibleMergeError as err:
logger.debug(traceback.format_exc())
logger.error(
"Encountered conflicting information when creating Records from the crawled "
f"data:\n\n{err}"
)
_update_status_record(crawler.run_id, 0, 0, status="FAILED")
return 1
except TransactionError as err:
logger.debug(traceback.format_exc())
logger.error(err)
logger.error("Transaction error details:")
for suberr in err.errors:
logger.error("---")
logger.error(suberr.msg)
logger.error(suberr.entity)
return 1
except Exception as err: except Exception as err:
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())
logger.error(err) logger.error(err)
# Special treatment for known error types
if "SHARED_DIR" in os.environ: if isinstance(err, ImpossibleMergeError):
# pylint: disable=E0601 logger.error(
domain = get_config_setting("public_host_url") "Encountered conflicting information when creating Records from the crawled "
logger.error("Unexpected Error: Please tell your administrator about this and provide " f"data:\n\n{err}"
f"the following path.\n{get_shared_resource_link(domain, debuglog_public)}") )
elif isinstance(err, TransactionError):
logger.error("Transaction error details:")
for suberr in err.errors:
logger.error("---")
logger.error(suberr.msg)
logger.error(suberr.entity)
# Unkown errors get a special message
elif not isinstance(err, (ConverterValidationError, ForbiddenTransaction)):
if "SHARED_DIR" in os.environ:
# pylint: disable=E0601
domain = get_config_setting("public_host_url")
logger.error("Unexpected Error: Please tell your administrator about this and provide "
f"the following path.\n{get_shared_resource_link(domain, debuglog_public)}")
_update_status_record(crawler.run_id, 0, 0, status="FAILED") _update_status_record(crawler.run_id, 0, 0, status="FAILED")
return 1 return 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment