From 6ca6f1390ca058617ff2de43950ec1b71b3dc824 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 5 Jan 2024 14:37:02 -0500 Subject: [PATCH] Catch errors in Django-Q2 email reporter --- cmsmanage/django_q2_admin_email_reporter.py | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cmsmanage/django_q2_admin_email_reporter.py b/cmsmanage/django_q2_admin_email_reporter.py index 6350a9c..4589101 100644 --- a/cmsmanage/django_q2_admin_email_reporter.py +++ b/cmsmanage/django_q2_admin_email_reporter.py @@ -1,4 +1,5 @@ import sys +import traceback from django.views.debug import ExceptionReporter from django.core import mail @@ -9,12 +10,15 @@ class AdminEmailReporter: pass def report(self): - reporter = ExceptionReporter(None, *sys.exc_info()) - message = f"Failed to run task\n{reporter.get_traceback_text()}" - html_message = reporter.get_traceback_html() - mail.mail_admins( - "Django Q task failed", - message, - # fail_silently=True, - html_message=html_message, - ) + try: + reporter = ExceptionReporter(None, *sys.exc_info()) + message = f"Failed to run task\n{reporter.get_traceback_text()}" + html_message = reporter.get_traceback_html() + mail.mail_admins( + "Django Q task failed", + message, + # fail_silently=True, + html_message=html_message, + ) + except Exception: + print(traceback.format_exc())