lint: excuse catching broad exceptions

This commit is contained in:
Iain Learmonth 2022-05-17 09:03:43 +01:00
parent 9797d8d119
commit fce594bbc4
2 changed files with 9 additions and 3 deletions

View file

@ -85,14 +85,18 @@ def run_job(job_cls: Type[BaseAutomation], *,
logging.warning("Not time to run this job yet") logging.warning("Not time to run this job yet")
return return
if not automation.enabled and not force: if not automation.enabled and not force:
logging.warning(f"job {job_cls.short_name} is disabled and --force not specified") logging.warning("job %s is disabled and --force not specified", job_cls.short_name)
return return
automation.state = AutomationState.RUNNING automation.state = AutomationState.RUNNING
db.session.commit() db.session.commit()
job: BaseAutomation = job_cls() job: BaseAutomation = job_cls()
try: try:
success, logs = job.automate() success, logs = job.automate()
except Exception as e: # We want to catch any and all exceptions that would cause problems here, because
# the error handling process isn't really handling the error, but rather causing it
# to be logged for investigation. Catching more specific exceptions would just mean that
# others go unrecorded and are difficult to debug.
except Exception as e: # pylint: disable=broad-except
tb = TracebackException.from_exception(e) tb = TracebackException.from_exception(e)
success = False success = False
logs = "".join(tb.format()) logs = "".join(tb.format())

View file

@ -68,7 +68,9 @@ def impot(model: db.Model) -> None:
db.session.add(x) db.session.add(x)
db.session.commit() db.session.commit()
logging.info("Import completed successfully") logging.info("Import completed successfully")
except Exception as e: # Many things can go wrong in the above, like IO, format or database errors.
# We catch all the errors and ensure the database transaction is rolled back, and log it.
except Exception as e: # pylint: disable=broad-except
logging.exception(e) logging.exception(e)
db.session.rollback() db.session.rollback()