From 6fe675dffc035db62d2348984745160bade594cb Mon Sep 17 00:00:00 2001 From: Vaclav Petras Date: Tue, 14 Jul 2026 02:43:34 -0400 Subject: [PATCH] grass.pygrass: Add the psycopg2 hint as an exception note The table connection raised a new ImportError with the hint as its message, so the message of the original error, which says which module is missing, was replaced by the hint. Add the hint as a note to the original error instead. From the Python documentation of BaseException.add_note(): "Add the string note to the exception's notes which appear in the standard traceback after the exception string." The traceback then shows both the missing module and the hint. Exception notes need Python 3.11, which is now the minimum version. --- python/grass/pygrass/vector/table.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/grass/pygrass/vector/table.py b/python/grass/pygrass/vector/table.py index 84f8b0244d9..637ee8b74f5 100644 --- a/python/grass/pygrass/vector/table.py +++ b/python/grass/pygrass/vector/table.py @@ -856,9 +856,11 @@ def connection(self): psycopg2.paramstyle = "qmark" db = " ".join(self.database.split(",")) return psycopg2.connect(db) - except ImportError: - er = "You need to install psycopg2 to connect with this table." - raise ImportError(er) + except ImportError as error: + error.add_note( + "You need to install psycopg2 to connect with this table." + ) + raise str_err = "Driver is not supported yet, pleas use: sqlite or pg" raise TypeError(str_err)