From: Daniele Varrazzo Date: Wed, 8 Jan 2025 00:23:41 +0000 (+0100) Subject: fix(debug): print exceptions eventually raised by libpq calls X-Git-Tag: 3.2.4~6^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0399033d4d3e7d8d5e0046ddcc81dddef0b9043;p=thirdparty%2Fpsycopg.git fix(debug): print exceptions eventually raised by libpq calls --- 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