Re: Improved transaction error handling
"James Henstridge" <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On 31/12/2007, Karsten Hilbert <[email protected]> wrote: > On Fri, Dec 28, 2007 at 05:50:09AM +0900, James Henstridge wrote: > > > This means that we can set an appropriate "pgcode" attribute on the > > exceptions, allowing for better error handling. > That would be great ! > > A related thing I have been working on is differentiating > exceptions raised when failing to establish connections to > the backend. I want to be able to differentiate faulty > credentials from other errors in order to present meaningful > messages to the user. > > Parsing the exception string for keywords works but only in > very controlled circumstances. One needs to know beforehand > which language to parse in. Even forcing lc_messages to 'C' > in the database default doesn't make sure English error > messages are returned. Apparently some messages are > translated (generated ?) at the libpq level. Forcing libpq > to C locale would mean not being able to set the proper > locale on the entire application using libpq via psycopg2. Yep, some exception strings definitely come from libpq. The prime example is the "could not connect to server" and "connection closed" errors where there is no server to receive the message from ... It might be worth filing a Postgres feature request for the library to expose error codes for these connection-oriented errors. > I'd be happy to contribute the (Python level) code once it > works reliably if anyone wants it. This will probably require libpq changes before you could handle these errors reliably (assuming I haven't missed some other API). James.