From ba7a0a300857e8cd0aa973abf5a39a0dca88ced1 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 15 Dec 2011 17:42:11 +0000 Subject: [PATCH] Raise DatabaseError instead of error with bad exception informations We can actually raise these exceptions in weird situations, e.g. see ticket #82. --- psycopg/pqpath.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 1f0d5da9..1cfe240a 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -157,7 +157,8 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres) const char *code = NULL; if (conn == NULL) { - PyErr_SetString(Error, "psycopg went psycotic and raised a null error"); + PyErr_SetString(DatabaseError, + "psycopg went psycotic and raised a null error"); return; } @@ -183,9 +184,11 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres) /* if the is no error message we probably called pq_raise without reason: we need to set an exception anyway because the caller will probably - raise and a meaningful message is better than an empty one */ + raise and a meaningful message is better than an empty one. + Note: it can happen without it being our error: see ticket #82 */ if (err == NULL || err[0] == '\0') { - PyErr_SetString(Error, "psycopg went psycotic without error set"); + PyErr_SetString(DatabaseError, + "error with no message from the libpq"); return; }