From b85afc2792e6fd8893475775b30e5f2e1b5b89cc Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Thu, 17 Feb 2022 21:25:50 +0500 Subject: [PATCH 1/3] Additional fatal PostgresSQL errors. --- core/debug.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/debug.py b/core/debug.py index e0800e0619..a2733b4116 100644 --- a/core/debug.py +++ b/core/debug.py @@ -219,7 +219,7 @@ def check_fatal_errors(t, v): logger.error("Exiting due to fatal error") os._exit(1) - xn = "%s.%s" % (t.__module__, t.__name__) + xn = f"{t.__module__}.{t.__name__}" if xn in { "pymongo.errors.AutoReconnect", "pymongo.errors.NotMasterError", @@ -230,11 +230,16 @@ def check_fatal_errors(t, v): die("Reconnecting to MongoDB: %s", v) elif xn == "pymongo.errors.ServerSelectionTimeoutError": die("Cannot select MongoDB master: %s", v) - elif xn == "django.db.utils.DatabaseError" and "server closed" in v: + elif ( + xn == "django.db.utils.DatabaseError" and "server closed" in v + ) or "pgbouncer cannot connect to server" in v: die("Failed to connect PostgreSQL: %s", v) - elif xn == "psycopg2.InterfaceError" and "connection already closed" in v: + elif ( + xn in {"psycopg2.InterfaceError", "django.db.utils.InterfaceError"} + and "connection already closed" in v + ): die("PostgreSQL connection closed: %s", v) - elif xn == "psycopg2.OperationalError": + elif xn in {"psycopg2.OperationalError", "django.db.utils.OperationalError"}: die("PostgreSQL operational error: %s", v) elif xn == "django.db.utils.DatabaseError": die("PostgreSQL database error: %s", v) @@ -251,21 +256,21 @@ def get_traceback(reverse=config.traceback.reverse, fp=None, exc_info=None): pass # noqa Ignore exceptions now = datetime.datetime.now() r = [ - "UNHANDLED EXCEPTION (%s)" % str(now), - "PROCESS: %s" % version.process, - "VERSION: %s" % version.version, + f"UNHANDLED EXCEPTION ({str(now)})", + f"PROCESS: {version.process}", + f"VERSION: {version.version}", ] if version.branch: - r += ["BRANCH: %s CHANGESET: %s" % (version.branch, version.changeset)] + r += [f"BRANCH: {version.branch} CHANGESET: {version.changeset}"] if fp: - r += ["ERROR FINGERPRINT: %s" % fp] + r += [f"ERROR FINGERPRINT: {fp}"] r += [ - "WORKING DIRECTORY: %s" % os.getcwd(), - "EXCEPTION: %s %s" % (t, v), + f"WORKING DIRECTORY: {os.getcwd()}", + f"EXCEPTION: {t} {v}", format_frames(get_traceback_frames(tb), reverse=reverse), ] if not reverse: - r += ["UNHANDLED EXCEPTION (%s)" % str(now), str(t), str(v)] + r += [f"UNHANDLED EXCEPTION ({str(now)})", str(t), str(v)] return "\n".join(smart_text(x, errors="ignore") for x in r) -- GitLab From b55696d0df2acc21bb1c29e43d2d5ffcc63d2312 Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Fri, 18 Feb 2022 10:15:06 +0500 Subject: [PATCH 2/3] Fix check_fatal_errors value processed. --- core/debug.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/debug.py b/core/debug.py index a2733b4116..495a04da18 100644 --- a/core/debug.py +++ b/core/debug.py @@ -15,6 +15,7 @@ import hashlib import pprint import traceback import uuid +from typing import Type # Third-party modules import orjson @@ -213,13 +214,13 @@ def format_frames(frames, reverse=config.traceback.reverse): return "\n".join(r) -def check_fatal_errors(t, v): +def check_fatal_errors(t: "Type", v: "Exception"): def die(msg, *args, **kwargs): logger.error(msg, *args, **kwargs) logger.error("Exiting due to fatal error") os._exit(1) - xn = f"{t.__module__}.{t.__name__}" + xn, v = f"{t.__module__}.{t.__name__}", str(v) if xn in { "pymongo.errors.AutoReconnect", "pymongo.errors.NotMasterError", @@ -253,6 +254,7 @@ def get_traceback(reverse=config.traceback.reverse, fp=None, exc_info=None): try: check_fatal_errors(t, v) except: # noqa + logger.error("Check fatal error raise exception. Skipping...") pass # noqa Ignore exceptions now = datetime.datetime.now() r = [ -- GitLab From fdfb9675e313f477df7c4b824228ef2643640f8b Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Fri, 18 Feb 2022 11:46:18 +0500 Subject: [PATCH 3/3] Fix pylint. --- core/debug.py | 1 - 1 file changed, 1 deletion(-) diff --git a/core/debug.py b/core/debug.py index 495a04da18..d58aed9b29 100644 --- a/core/debug.py +++ b/core/debug.py @@ -255,7 +255,6 @@ def get_traceback(reverse=config.traceback.reverse, fp=None, exc_info=None): check_fatal_errors(t, v) except: # noqa logger.error("Check fatal error raise exception. Skipping...") - pass # noqa Ignore exceptions now = datetime.datetime.now() r = [ f"UNHANDLED EXCEPTION ({str(now)})", -- GitLab