From 57236b83b83cbfb588fcfcf70c1ca81c62d05a5b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 11 May 2025 22:48:26 +0200 Subject: [PATCH] chore: add PostgreSQL 18 exceptions --- docs/api/errors.rst | 8 ++++++++ psycopg/psycopg/errors.py | 12 ++++++++++++ tools/update_errors.py | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/api/errors.rst b/docs/api/errors.rst index 10301867f..ab35c0f02 100644 --- a/docs/api/errors.rst +++ b/docs/api/errors.rst @@ -241,6 +241,9 @@ SQLSTATE Exception Base exception --------------------------------------------------------------------------------- ``0Z000`` `!DiagnosticsException` `!DatabaseError` ``0Z002`` `!StackedDiagnosticsAccessedWithoutActiveHandler` `!DatabaseError` +**Class 10** - XQuery Error +--------------------------------------------------------------------------------- +``10608`` `!InvalidArgumentForXquery` `!ProgrammingError` **Class 20** - Case Not Found --------------------------------------------------------------------------------- ``20000`` `!CaseNotFound` `!ProgrammingError` @@ -487,6 +490,7 @@ SQLSTATE Exception Base exception ``58030`` `!IoError` `!OperationalError` ``58P01`` `!UndefinedFile` `!OperationalError` ``58P02`` `!DuplicateFile` `!OperationalError` +``58P03`` `!FileNameTooLong` `!OperationalError` **Class 72** - Snapshot Failure --------------------------------------------------------------------------------- ``72000`` `!SnapshotTooOld` `!DatabaseError` @@ -544,3 +548,7 @@ SQLSTATE Exception Base exception .. versionadded:: 3.2.3 Exception `!TransactionTimeout`, introduced in PostgreSQL 17. + +.. versionadded:: 3.2.10 + Exception `!InvalidArgumentForXquery`, `FileNameTooLong`, introduced in + PostgreSQL 18. diff --git a/psycopg/psycopg/errors.py b/psycopg/psycopg/errors.py index fd514f0ea..468957dc4 100644 --- a/psycopg/psycopg/errors.py +++ b/psycopg/psycopg/errors.py @@ -579,6 +579,7 @@ def get_base_exception(sqlstate: str) -> type[Error]: _base_exc_map = { "08": OperationalError, # Connection Exception "0A": NotSupportedError, # Feature Not Supported + "10": ProgrammingError, # XQuery Error "20": ProgrammingError, # Case Not Foud "21": ProgrammingError, # Cardinality Violation "22": DataError, # Data Exception @@ -728,6 +729,13 @@ class StackedDiagnosticsAccessedWithoutActiveHandler(DatabaseError, pass +# Class 10 - XQuery Error + +class InvalidArgumentForXquery(ProgrammingError, + code='10608', name='INVALID_ARGUMENT_FOR_XQUERY'): + pass + + # Class 20 - Case Not Found class CaseNotFound(ProgrammingError, @@ -1581,6 +1589,10 @@ class DuplicateFile(OperationalError, code='58P02', name='DUPLICATE_FILE'): pass +class FileNameTooLong(OperationalError, + code='58P03', name='FILE_NAME_TOO_LONG'): + pass + # Class 72 - Snapshot Failure diff --git a/tools/update_errors.py b/tools/update_errors.py index bc1264492..72ee9d4e1 100755 --- a/tools/update_errors.py +++ b/tools/update_errors.py @@ -22,7 +22,7 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(mess def main(): - classes, errors = fetch_errors("9.6 10 11 12 13 14 15 16 17".split()) + classes, errors = fetch_errors("9.6 10 11 12 13 14 15 16 17 18".split()) fn = os.path.dirname(__file__) + "/../psycopg/psycopg/errors.py" update_file(fn, generate_module_data(classes, errors)) -- 2.47.3