]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(debug): print exceptions eventually raised by libpq calls
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jan 2025 00:23:41 +0000 (01:23 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 8 Jan 2025 12:41:56 +0000 (13:41 +0100)
psycopg/psycopg/pq/_debug.py

index 70855c55d08a2fabd491a79f10dde33023102d60..13e995435ab5dba4a21b1661117966883f752b2f 100644 (file)
@@ -93,12 +93,17 @@ def debugging(f: Func) -> Func:
             reprs.append(f"{k}={v!r}")
 
         logger.info("PGconn.%s(%s)", f.__name__, ", ".join(reprs))
-        rv = f(*args, **kwargs)
-        # Display the return value only if the function is declared to return
-        # something else than None.
-        ra = inspect.signature(f).return_annotation
-        if ra is not None or rv is not None:
-            logger.info("    <- %r", rv)
-        return rv
+        try:
+            rv = f(*args, **kwargs)
+        except Exception as ex:
+            logger.info("    <- %r", ex)
+            raise
+        else:
+            # Display the return value only if the function is declared to return
+            # something else than None.
+            ra = inspect.signature(f).return_annotation
+            if ra is not None or rv is not None:
+                logger.info("    <- %r", rv)
+            return rv
 
     return debugging_  # type: ignore