diff --git a/app/cli/automate.py b/app/cli/automate.py index 8c9d836..a8dd090 100644 --- a/app/cli/automate.py +++ b/app/cli/automate.py @@ -85,14 +85,18 @@ def run_job(job_cls: Type[BaseAutomation], *, logging.warning("Not time to run this job yet") return 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 automation.state = AutomationState.RUNNING db.session.commit() job: BaseAutomation = job_cls() try: 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) success = False logs = "".join(tb.format()) diff --git a/app/cli/db.py b/app/cli/db.py index 2d56e85..59a20e2 100644 --- a/app/cli/db.py +++ b/app/cli/db.py @@ -68,7 +68,9 @@ def impot(model: db.Model) -> None: db.session.add(x) db.session.commit() 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) db.session.rollback()