mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Raise DatabaseError instead of error with bad exception informations
We can actually raise these exceptions in weird situations, e.g. see ticket #82.
This commit is contained in:
parent
424bc310a6
commit
ba7a0a3008
|
@ -157,7 +157,8 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres)
|
||||||
const char *code = NULL;
|
const char *code = NULL;
|
||||||
|
|
||||||
if (conn == 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;
|
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:
|
/* 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
|
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') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user