Avoid crash when a psycopg DatabaseError has no info from the db
authorKarl O. Pinc <kop@karlpinc.com>
Sat, 22 Jun 2024 04:21:32 +0000 (23:21 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sat, 22 Jun 2024 04:21:32 +0000 (23:21 -0500)
src/pgwui_core/exceptions.py

index 0fd7b1f2106a9979253c61c5ce74edb4b6f6d03b..e9be180d35b552cde5ff0b674005611b6fabf309 100644 (file)
@@ -204,7 +204,12 @@ class DBError(SetupError):
         Produce an html formatted message from a psycopg3 DatabaseError
         exception.
         '''
-        primary = html_escape(ex.diag.message_primary)
+        if ex.diag.message_primary is None:
+            # Produce _something_ in those cases where the message is from
+            # psycopg and not the db.
+            primary = str(ex)
+        else:
+            primary = html_escape(ex.diag.message_primary)
 
         if ex.diag.message_detail is None:
             detail = ''