A few client tools duplicate error messages already provided by libpq,
such as
pg_rewind: fatal: could not connect to server: could not connect to
server: No such file or directory
pg_basebackup: error: could not connect to server: could not connect to
server: No such file or directory
psql: error: could not connect to server: could not connect to server:
No such file or directory
The psql case is actually a regression introduced in PG12, but the other
two appear to be ancient.
Other client tools provide a different error message so in aggregate it
looks like this:
createdb: error: could not connect to database template1: could not
connect to server: No such file or directory
The attached patch removes the redundant message from the client tools.
I suppose it's a bit dubious because there is no guarantee what the
level of detail the message supplied by libpq has. But I think these
few cases are not particularly hard to keep in sync.
From a2c1e26ceff05ec6ebbdb9cf74a3171ebf969911 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 5 Nov 2020 13:24:47 +0100
Subject: [PATCH] Fix redundant error messages in client tools
A few client tools duplicate error messages already provided by libpq.
---
src/bin/pg_basebackup/streamutil.c | 5 ++---
src/bin/pg_rewind/pg_rewind.c | 3 +--
src/bin/psql/startup.c | 2 +-
3 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/bin/pg_basebackup/streamutil.c
b/src/bin/pg_basebackup/streamutil.c
index be653ebb2d..5c536eb5fd 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -183,7 +183,7 @@ GetConnection(void)
*/
if (!tmpconn)
{
- pg_log_error("could not connect to server");
+ pg_log_error("out of memory");
exit(1);
}
@@ -200,8 +200,7 @@ GetConnection(void)
if (PQstatus(tmpconn) != CONNECTION_OK)
{
- pg_log_error("could not connect to server: %s",
- PQerrorMessage(tmpconn));
+ pg_log_error("%s", PQerrorMessage(tmpconn));
PQfinish(tmpconn);
free(values);
free(keywords);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 421a45ef5b..52e3fc40e8 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -282,8 +282,7 @@ main(int argc, char **argv)
conn = PQconnectdb(connstr_source);
if (PQstatus(conn) == CONNECTION_BAD)
- pg_fatal("could not connect to server: %s",
- PQerrorMessage(conn));
+ pg_fatal("%s", PQerrorMessage(conn));
if (showprogress)
pg_log_info("connected to server");
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index e8d35a108f..586fcb3366 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -295,7 +295,7 @@ main(int argc, char *argv[])
if (PQstatus(pset.db) == CONNECTION_BAD)
{
- pg_log_error("could not connect to server: %s",
PQerrorMessage(pset.db));
+ pg_log_error("%s", PQerrorMessage(pset.db));
PQfinish(pset.db);
exit(EXIT_BADCONN);
}
--
2.28.0