From: Daniele Varrazzo Date: Fri, 8 Oct 2021 01:25:46 +0000 (+0200) Subject: Hide long tracebacks on connect X-Git-Tag: 3.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91b1605f6eb50b7374418a73a6d8e2cfe4240a7b;p=thirdparty%2Fpsycopg.git Hide long tracebacks on connect Only hide tracebacks of errors coming from the database. They just come from the database: seeing exactly where they explode inside psycopg is not useful for the end user. Especially given the generator/waiting interaction. See https://github.com/psycopg/psycopg/issues/99 for an example of not particularly helpful traceback (the message is the only useful bit). --- diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 3d9258dca..aeca92668 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -560,10 +560,14 @@ class Connection(BaseConnection[Row]): params = cls._get_connection_params(conninfo, **kwargs) conninfo = make_conninfo(**params) - rv = cls._wait_conn( - cls._connect_gen(conninfo, autocommit=autocommit), - timeout=params["connect_timeout"], - ) + try: + rv = cls._wait_conn( + cls._connect_gen(conninfo, autocommit=autocommit), + timeout=params["connect_timeout"], + ) + except e.Error as ex: + raise ex.with_traceback(None) + if row_factory: rv.row_factory = row_factory if context: diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index f29129599..69b8bee0b 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -105,10 +105,14 @@ class AsyncConnection(BaseConnection[Row]): params = await cls._get_connection_params(conninfo, **kwargs) conninfo = make_conninfo(**params) - rv = await cls._wait_conn( - cls._connect_gen(conninfo, autocommit=autocommit), - timeout=params["connect_timeout"], - ) + try: + rv = await cls._wait_conn( + cls._connect_gen(conninfo, autocommit=autocommit), + timeout=params["connect_timeout"], + ) + except e.Error as ex: + raise ex.with_traceback(None) + if row_factory: rv.row_factory = row_factory if context: