From e83f635c5dbafa6d7c2de6c2b9a111b4fd906e55 Mon Sep 17 00:00:00 2001 From: Yugo Nagata Date: Thu, 10 Jul 2025 17:21:05 +0900 Subject: [PATCH v9 3/3] Improve error messages for errors that cause client abortion This commit modifies relevant error messages to explicitly indicate that the client was aborted. As part of this change, pg_log_error was replaced with commandFailed(). --- src/bin/pgbench/pgbench.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 7dbeb79ca8d..3e855c1b0aa 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -3309,8 +3309,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) case PGRES_EMPTY_QUERY: /* may be used for testing no-op overhead */ if (is_last && meta == META_GSET) { - pg_log_error("client %d script %d command %d query %d: expected one row, got %d", - st->id, st->use_file, st->command, qrynum, 0); + commandFailed(st, "gset", psprintf("expected one row, got %d", 0)); st->estatus = ESTATUS_META_COMMAND_ERROR; goto error; } @@ -3324,8 +3323,7 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) if (meta == META_GSET && ntuples != 1) { /* under \gset, report the error */ - pg_log_error("client %d script %d command %d query %d: expected one row, got %d", - st->id, st->use_file, st->command, qrynum, PQntuples(res)); + commandFailed(st, "gset", psprintf("expected one row, got %d", PQntuples(res))); st->estatus = ESTATUS_META_COMMAND_ERROR; goto error; } @@ -3339,18 +3337,18 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) for (int fld = 0; fld < PQnfields(res); fld++) { char *varname = PQfname(res, fld); + char *cmd = (meta == META_ASET ? "aset" : "gset"); /* allocate varname only if necessary, freed below */ if (*varprefix != '\0') varname = psprintf("%s%s", varprefix, varname); /* store last row result as a string */ - if (!putVariable(&st->variables, meta == META_ASET ? "aset" : "gset", varname, + if (!putVariable(&st->variables, cmd, varname, PQgetvalue(res, ntuples - 1, fld))) { /* internal error */ - pg_log_error("client %d script %d command %d query %d: error storing into variable %s", - st->id, st->use_file, st->command, qrynum, varname); + commandFailed(st, cmd, psprintf("error storing into variable %s", varname)); st->estatus = ESTATUS_META_COMMAND_ERROR; goto error; } @@ -3385,8 +3383,8 @@ readCommandResponse(CState *st, MetaCommand meta, char *varprefix) default: /* anything else is unexpected */ - pg_log_error("client %d script %d aborted in command %d query %d: %s", - st->id, st->use_file, st->command, qrynum, + pg_log_error("client %d aborted in command %d query %d of script %d: %s", + st->id, st->command, qrynum, st->use_file, PQerrorMessage(st->con)); goto error; } -- 2.39.5 (Apple Git-154)