summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/_static/psycopg.css4
-rw-r--r--doc/src/errorcodes.rst41
-rw-r--r--lib/errorcodes.py4
-rwxr-xr-xscripts/make_errorcodes.py5
4 files changed, 47 insertions, 7 deletions
diff --git a/doc/src/_static/psycopg.css b/doc/src/_static/psycopg.css
index df52b32..5cb9284 100644
--- a/doc/src/_static/psycopg.css
+++ b/doc/src/_static/psycopg.css
@@ -1,5 +1,9 @@
@import url("default.css");
+blockquote {
+ font-style: italic;
+}
+
div.admonition-todo {
background-color: #ffa;
border: 1px solid #ee2;
diff --git a/doc/src/errorcodes.rst b/doc/src/errorcodes.rst
index e1c76c0..a0c1033 100644
--- a/doc/src/errorcodes.rst
+++ b/doc/src/errorcodes.rst
@@ -3,13 +3,20 @@
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
+.. index::
+ single: Error; Codes
+
.. module:: psycopg2.errorcodes
+.. testsetup:: *
+
+ from psycopg2 import errorcodes
+
.. versionadded:: 2.0.6
-This module contains symbolic names for all PostgreSQL error codes.
-Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error code available
-in the :attr:`~psycopg2.Error.pgcode` attribute.
+This module contains symbolic names for all PostgreSQL error codes and error
+classes codes. Subclasses of :exc:`~psycopg2.Error` make the PostgreSQL error
+code available in the :attr:`~psycopg2.Error.pgcode` attribute.
From PostgreSQL documentation:
@@ -30,12 +37,36 @@ From PostgreSQL documentation:
recognize the specific error code can still be able to infer what to do
from the error class.
-
.. seealso:: `PostgreSQL Error Codes table`__
.. __: http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html#ERRCODES-TABLE
-.. todo:: errors table
+An example of the available constants defined in the module:
+
+ >>> errorcodes.CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
+ '42'
+ >>> errorcodes.UNDEFINED_TABLE
+ '42P01'
+
+Constants representing all the error values documented by PostgreSQL versions
+between 8.1 and 8.4 are included in the module.
+
+
+.. autofunction:: lookup(code)
+
+ .. doctest::
+
+ >>> try:
+ ... cur.execute("SELECT ouch FROM aargh;")
+ ... except Exception, e:
+ ... pass
+ ...
+ >>> errorcodes.lookup(e.pgcode[:2])
+ 'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'
+ >>> errorcodes.lookup(e.pgcode)
+ 'UNDEFINED_TABLE'
+
+ .. versionadded:: 2.0.14
diff --git a/lib/errorcodes.py b/lib/errorcodes.py
index 3720697..9567201 100644
--- a/lib/errorcodes.py
+++ b/lib/errorcodes.py
@@ -30,9 +30,9 @@ This module contains symbolic names for all PostgreSQL error codes.
#
def lookup(code, _cache={}):
- """Lookup a code error and return its symbolic name.
+ """Lookup an error code or class code and return its symbolic name.
- Raise KeyError if the code is not found.
+ Raise :exc:`KeyError` if the code is not found.
"""
if _cache:
return _cache[code]
diff --git a/scripts/make_errorcodes.py b/scripts/make_errorcodes.py
index 3dad76a..64ebca3 100755
--- a/scripts/make_errorcodes.py
+++ b/scripts/make_errorcodes.py
@@ -71,6 +71,11 @@ def parse_errors(url):
errcode = tr.tt.string.encode("ascii")
assert len(errcode) == 5
errlabel = tr('td')[1].string.replace(" ", "_").encode("ascii")
+
+ # double check the columns are equal
+ cond_name = tr('td')[2].string.upper().encode("ascii")
+ assert errlabel == cond_name, tr
+
errors[class_][errcode] = errlabel
return classes, errors