diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2022-11-15 11:50:04 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2022-11-15 12:16:50 +0100 |
commit | a9e9a9f32b35edf129c88e8b929ef223f8511f59 (patch) | |
tree | bf6081551ddd6dc77c66bc5dad0d6cf11d4a919c /src/interfaces/libpq/fe-protocol3.c | |
parent | 0873b2d354b9c73a69067c0afb92e35994adc47e (diff) | |
download | postgresql-a9e9a9f32b35edf129c88e8b929ef223f8511f59.tar.gz postgresql-a9e9a9f32b35edf129c88e8b929ef223f8511f59.zip |
libpq error message refactoring, part 2
This applies the new APIs to the code.
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/7c0232ef-7b44-68db-599d-b327d0640a77@enterprisedb.com
Diffstat (limited to 'src/interfaces/libpq/fe-protocol3.c')
-rw-r--r-- | src/interfaces/libpq/fe-protocol3.c | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index f5664e0f831..88dd360c905 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -201,8 +201,7 @@ pqParseInput3(PGconn *conn) PGRES_COMMAND_OK); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } } @@ -226,8 +225,7 @@ pqParseInput3(PGconn *conn) PGRES_PIPELINE_SYNC); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } else @@ -255,8 +253,7 @@ pqParseInput3(PGconn *conn) PGRES_EMPTY_QUERY); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } } @@ -273,8 +270,7 @@ pqParseInput3(PGconn *conn) PGRES_COMMAND_OK); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } } @@ -354,8 +350,7 @@ pqParseInput3(PGconn *conn) PGRES_COMMAND_OK); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } } @@ -387,8 +382,7 @@ pqParseInput3(PGconn *conn) else { /* Set up to report error at end of query */ - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("server sent data (\"D\" message) without prior row description (\"T\" message)\n")); + libpq_append_conn_error(conn, "server sent data (\"D\" message) without prior row description (\"T\" message)"); pqSaveErrorResult(conn); /* Discard the unexpected message */ conn->inCursor += msgLength; @@ -430,9 +424,7 @@ pqParseInput3(PGconn *conn) */ break; default: - appendPQExpBuffer(&conn->errorMessage, - libpq_gettext("unexpected response from server; first received character was \"%c\"\n"), - id); + libpq_append_conn_error(conn, "unexpected response from server; first received character was \"%c\"", id); /* build an error result holding the error message */ pqSaveErrorResult(conn); /* not sure if we will see more, so go to ready state */ @@ -455,9 +447,7 @@ pqParseInput3(PGconn *conn) else { /* Trouble --- report it */ - appendPQExpBuffer(&conn->errorMessage, - libpq_gettext("message contents do not agree with length in message type \"%c\"\n"), - id); + libpq_append_conn_error(conn, "message contents do not agree with length in message type \"%c\"", id); /* build an error result holding the error message */ pqSaveErrorResult(conn); conn->asyncStatus = PGASYNC_READY; @@ -475,8 +465,7 @@ pqParseInput3(PGconn *conn) static void handleSyncLoss(PGconn *conn, char id, int msgLength) { - appendPQExpBuffer(&conn->errorMessage, - libpq_gettext("lost synchronization with server: got message type \"%c\", length %d\n"), + libpq_append_conn_error(conn, "lost synchronization with server: got message type \"%c\", length %d", id, msgLength); /* build an error result holding the error message */ pqSaveErrorResult(conn); @@ -967,8 +956,7 @@ pqGetErrorNotice3(PGconn *conn, bool isError) } if (PQExpBufferDataBroken(workBuf)) - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); else appendPQExpBufferStr(&conn->errorMessage, workBuf.data); } @@ -1723,8 +1711,7 @@ pqGetCopyData3(PGconn *conn, char **buffer, int async) *buffer = (char *) malloc(msgLength + 1); if (*buffer == NULL) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); return -2; } memcpy(*buffer, &conn->inBuffer[conn->inCursor], msgLength); @@ -1756,8 +1743,7 @@ pqGetline3(PGconn *conn, char *s, int maxlen) conn->asyncStatus != PGASYNC_COPY_BOTH) || conn->copy_is_binary) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("PQgetline: not doing text COPY OUT\n")); + libpq_append_conn_error(conn, "PQgetline: not doing text COPY OUT"); *s = '\0'; return EOF; } @@ -1862,8 +1848,7 @@ pqEndcopy3(PGconn *conn) conn->asyncStatus != PGASYNC_COPY_OUT && conn->asyncStatus != PGASYNC_COPY_BOTH) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("no COPY in progress\n")); + libpq_append_conn_error(conn, "no COPY in progress"); return 1; } @@ -2126,15 +2111,13 @@ pqFunctionCall3(PGconn *conn, Oid fnid, conn->result = PQmakeEmptyPGresult(conn, status); if (!conn->result) { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("out of memory\n")); + libpq_append_conn_error(conn, "out of memory"); pqSaveErrorResult(conn); } } else { - appendPQExpBufferStr(&conn->errorMessage, - libpq_gettext("protocol error: no function result\n")); + libpq_append_conn_error(conn, "protocol error: no function result"); pqSaveErrorResult(conn); } } @@ -2145,9 +2128,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid, break; default: /* The backend violates the protocol. */ - appendPQExpBuffer(&conn->errorMessage, - libpq_gettext("protocol error: id=0x%x\n"), - id); + libpq_append_conn_error(conn, "protocol error: id=0x%x", id); pqSaveErrorResult(conn); /* trust the specified message length as what to skip */ conn->inStart += 5 + msgLength; |