Skip to content

Commit 27a48e5

Browse files
committed
Improve new wording of libpq's connection failure messages.
"connection to server so-and-so failed:" seems clearer than the previous wording "could not connect to so-and-so:" (introduced by 52a1022), because the latter suggests a network-level connection failure. We're now prefixing this string to all types of connection failures, for instance authentication failures; so we need wording that doesn't imply a low-level error. Per discussion with Robert Haas. Discussion: https://postgr.es/m/CA+TgmobssJ6rS22dspWnu-oDxXevGmhMD8VcRBjmj-b9UDqRjw@mail.gmail.com
1 parent 55dc86e commit 27a48e5

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@
34603460
34613461
command_fails_like(
34623462
[ 'pg_dump', '-p', "$port", 'qqq' ],
3463-
qr/pg_dump: error: connection to database "qqq" failed: could not connect to .*: FATAL: database "qqq" does not exist/,
3463+
qr/pg_dump: error: connection to database "qqq" failed: connection to server .* failed: FATAL: database "qqq" does not exist/,
34643464
'connecting to a non-existent database');
34653465
34663466
#########################################

src/interfaces/ecpg/test/expected/connect-test5.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
[NO_PID]: sqlca: code: 0, state: 00000
3737
[NO_PID]: ECPGconnect: opening database <DEFAULT> on <DEFAULT> port <DEFAULT> for user regress_ecpg_user2
3838
[NO_PID]: sqlca: code: 0, state: 00000
39-
[NO_PID]: ECPGconnect: could not open database: could not connect: FATAL: database "regress_ecpg_user2" does not exist
39+
[NO_PID]: ECPGconnect: could not open database: connection to server failed: FATAL: database "regress_ecpg_user2" does not exist
4040

4141
[NO_PID]: sqlca: code: 0, state: 00000
4242
[NO_PID]: ecpg_finish: connection main closed
@@ -73,7 +73,7 @@
7373
[NO_PID]: sqlca: code: -220, state: 08003
7474
[NO_PID]: ECPGconnect: opening database <DEFAULT> on <DEFAULT> port <DEFAULT> for user regress_ecpg_user2
7575
[NO_PID]: sqlca: code: 0, state: 00000
76-
[NO_PID]: ECPGconnect: could not open database: could not connect: FATAL: database "regress_ecpg_user2" does not exist
76+
[NO_PID]: ECPGconnect: could not open database: connection to server failed: FATAL: database "regress_ecpg_user2" does not exist
7777

7878
[NO_PID]: sqlca: code: 0, state: 00000
7979
[NO_PID]: ecpg_finish: connection main closed

src/interfaces/ecpg/test/pg_regress_ecpg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ecpg_filter_source(const char *sourcefile, const char *outfile)
8080
}
8181

8282
/*
83-
* Remove the details of "could not connect to ...: " error messages
83+
* Remove the details of connection failure error messages
8484
* in a test result file, since the target host/pathname and/or port
8585
* can vary. Rewrite the result file in-place.
8686
*
@@ -113,15 +113,15 @@ ecpg_filter_stderr(const char *resultfile, const char *tmpfile)
113113

114114
while (pg_get_line_buf(s, &linebuf))
115115
{
116-
char *p1 = strstr(linebuf.data, "could not connect to ");
116+
char *p1 = strstr(linebuf.data, "connection to server ");
117117

118118
if (p1)
119119
{
120-
char *p2 = strstr(p1, ": ");
120+
char *p2 = strstr(p1, "failed: ");
121121

122122
if (p2)
123123
{
124-
memmove(p1 + 17, p2, strlen(p2) + 1);
124+
memmove(p1 + 21, p2, strlen(p2) + 1);
125125
/* we don't bother to fix up linebuf.len */
126126
}
127127
}

src/interfaces/libpq/fe-connect.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,17 +1668,16 @@ getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
16681668
host_addr[0] = '\0';
16691669
}
16701670

1671-
/* ----------
1672-
* emitCouldNotConnect -
1673-
* Speculatively append "could not connect to ...: " to conn->errorMessage
1674-
* once we've identified the current connection target address. This ensures
1675-
* that any subsequent error message will be properly attributed to the
1676-
* server we couldn't connect to. conn->raddr must be valid, and the result
1677-
* of getHostaddr() must be supplied.
1678-
* ----------
1671+
/*
1672+
* emitHostIdentityInfo -
1673+
* Speculatively append "connection to server so-and-so failed: " to
1674+
* conn->errorMessage once we've identified the current connection target
1675+
* address. This ensures that any subsequent error message will be properly
1676+
* attributed to the server we couldn't connect to. conn->raddr must be
1677+
* valid, and the result of getHostaddr() must be supplied.
16791678
*/
16801679
static void
1681-
emitCouldNotConnect(PGconn *conn, const char *host_addr)
1680+
emitHostIdentityInfo(PGconn *conn, const char *host_addr)
16821681
{
16831682
#ifdef HAVE_UNIX_SOCKETS
16841683
if (IS_AF_UNIX(conn->raddr.addr.ss_family))
@@ -1690,7 +1689,7 @@ emitCouldNotConnect(PGconn *conn, const char *host_addr)
16901689
service, sizeof(service),
16911690
NI_NUMERICSERV);
16921691
appendPQExpBuffer(&conn->errorMessage,
1693-
libpq_gettext("could not connect to socket \"%s\": "),
1692+
libpq_gettext("connection to server on socket \"%s\" failed: "),
16941693
service);
16951694
}
16961695
else
@@ -1717,12 +1716,12 @@ emitCouldNotConnect(PGconn *conn, const char *host_addr)
17171716
host_addr[0] &&
17181717
strcmp(displayed_host, host_addr) != 0)
17191718
appendPQExpBuffer(&conn->errorMessage,
1720-
libpq_gettext("could not connect to host \"%s\" (%s), port %s: "),
1719+
libpq_gettext("connection to server at \"%s\" (%s), port %s failed: "),
17211720
displayed_host, host_addr,
17221721
displayed_port);
17231722
else
17241723
appendPQExpBuffer(&conn->errorMessage,
1725-
libpq_gettext("could not connect to host \"%s\", port %s: "),
1724+
libpq_gettext("connection to server at \"%s\", port %s failed: "),
17261725
displayed_host,
17271726
displayed_port);
17281727
}
@@ -2524,7 +2523,7 @@ PQconnectPoll(PGconn *conn)
25242523
conn->try_next_addr = true;
25252524
goto keep_going;
25262525
}
2527-
emitCouldNotConnect(conn, host_addr);
2526+
emitHostIdentityInfo(conn, host_addr);
25282527
appendPQExpBuffer(&conn->errorMessage,
25292528
libpq_gettext("could not create socket: %s\n"),
25302529
SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)));
@@ -2534,9 +2533,11 @@ PQconnectPoll(PGconn *conn)
25342533
/*
25352534
* Once we've identified a target address, all errors
25362535
* except the preceding socket()-failure case should be
2537-
* prefixed with "could not connect to <target>: ".
2536+
* prefixed with host-identity information. (If the
2537+
* connection succeeds, the contents of conn->errorMessage
2538+
* won't matter, so this is harmless.)
25382539
*/
2539-
emitCouldNotConnect(conn, host_addr);
2540+
emitHostIdentityInfo(conn, host_addr);
25402541

25412542
/*
25422543
* Select socket options: no delay of outgoing data for

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy