Re: finer exception handling

Karsten Hilbert <[email protected]> Fri, 21 May 2010 23:22:07 +0200
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Wed, May 19, 2010 at 05:55:46PM -0400, albert wrote:

> I need to handle an exception test case to distinguish the following results
> out of a query:
> 
> 1. the postgres server is down
> 2. the login password is wrong
> 3. the database does not exist

The PostgreSQL people do not (for security reasons) want to
give specific error feedback on whether the user name, the
password, or anything else permission related is the cause
of a connection problem.

Your cases 2 and 3 may fall in this category.

> I can't find a way to classify the error cases mentioned above. The pgerror
> and pgcode exception variables arrive as None objects to me whenever I catch
> any of the exceptions. I can't rely on the error messages as my application
> is multilingual.

The problem is even worse: the early PG error messages do
not depend on the client locale - they depend on the
*server* locale -- which you cannot programmatically know
before a successful connection has been established ...

:-(

I have tried to make the PostgreSQL folks aware of this
problem, it's been noted and somewhat discussed, but it
seems of rather low impact.

Karsten
-- 
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346