From 61b18b5dba1a2d13ac81ca960e6e21b2c2260c79 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 8 Jan 2025 01:23:41 +0100 Subject: [PATCH] fix(debug): print exceptions eventually raised by libpq calls --- psycopg/psycopg/pq/_debug.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/psycopg/psycopg/pq/_debug.py b/psycopg/psycopg/pq/_debug.py index 70855c55d..13e995435 100644 --- a/psycopg/psycopg/pq/_debug.py +++ b/psycopg/psycopg/pq/_debug.py @@ -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 -- 2.47.3