Only send exception mails from production environment

This commit is contained in:
Keith Edmunds 2023-02-18 18:11:19 +00:00
parent a41aea2d36
commit 1c294e1ce4
2 changed files with 7 additions and 5 deletions

View File

@ -76,7 +76,7 @@ def log_uncaught_exceptions(_ex_cls, ex, tb):
logging.critical(''.join(traceback.format_tb(tb)))
print("\033[1;37;40m")
print(stackprinter.format(ex, style="darkbg2", add_summary=True))
if os.environ["MM_ENV"] != "DEVELOPMENT":
if os.environ["MM_ENV"] == "PRODUCTION":
msg = stackprinter.format(ex)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg)

View File

@ -3,6 +3,7 @@
from log import log
from os.path import basename
import argparse
import os
import stackprinter # type: ignore
import subprocess
import sys
@ -1965,11 +1966,12 @@ if __name__ == "__main__":
engine.dispose()
sys.exit(status)
except Exception as exc:
from helpers import send_mail
if os.environ["MM_ENV"] == "PRODUCTION":
from helpers import send_mail
msg = stackprinter.format(exc)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg)
msg = stackprinter.format(exc)
send_mail(Config.ERRORS_TO, Config.ERRORS_FROM,
"Exception from musicmuster", msg)
print("\033[1;31;47mUnhandled exception starts")
stackprinter.show(style="darkbg")