From 5e3334e93e3a893c5ebfc8dc5f75b046d34d16d9 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 21 Jun 2024 23:21:32 -0500 Subject: [PATCH] Avoid crash when a psycopg DatabaseError has no info from the db --- src/pgwui_core/exceptions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pgwui_core/exceptions.py b/src/pgwui_core/exceptions.py index 0fd7b1f..e9be180 100644 --- a/src/pgwui_core/exceptions.py +++ b/src/pgwui_core/exceptions.py @@ -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 = '' -- 2.34.1