Make message strings in fe-connect.c consistent

From: Gurjeet Singh <gurjeet(at)singh(dot)im>
To: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Make message strings in fe-connect.c consistent
Date: 2023-04-21 04:28:01
Message-ID: CABwTF4Xu3g9zohJ9obu8m7MKbf8g63NgpRDjwqPHQgAtB+Gb8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

When reviewing a recently committed patch [1] I noticed the odd usage
of a format specifier:

+ libpq_append_conn_error(conn, "invalid %s value: \"%s\"",
+ "load_balance_hosts",
+ conn->load_balance_hosts);

The oddity is that the first %s is unnecessary, since the value we
want there is a constant. Typically a format specifier used to get the
value stored in a variable.

Upon closer look, it looks like this is a common pattern in
fe-connect.c; there are many places where a %s format specifier is
being used in the format sting, where the name of the parameter would
have sufficed.

Upon some research, the only explanation I could come up with was that
this pattern of specifying error messages helps with message
translations. This way there's just one message to be translated. For
example:

.../libpq/po/es.po-#: fe-connect.c:1268 fe-connect.c:1294
fe-connect.c:1336 fe-connect.c:1345
.../libpq/po/es.po-#: fe-connect.c:1378 fe-connect.c:1422
.../libpq/po/es.po-#, c-format
.../libpq/po/es.po:msgid "invalid %s value: \"%s\"\n"

There's just one exception to this pattern, though.

> libpq_append_conn_error(conn, "invalid require_auth method: \"%s\"",
> method);

So, to make it consistent throughout the file, we should either
replace all such %s format specifiers with the respective strings, or
use the same pattern for the message string used for require_method,
as well. Attached patch [2] does the former, and patch [3] does the
latter.

Pick your favorite one.

[1]: Support connection load balancing in libpq
7f5b19817eaf38e70ad1153db4e644ee9456853e

[2]: Replace placeholders with known strings
v1-0001-Replace-placeholders-with-known-strings.patch

[3]: Make require_auth error message similar to surrounding messages
v1-0001-Make-require_auth-error-message-similar-to-surrou.patch

Best regards,
Gurjeet http://Gurje.et
Postgres Contributors Team, http://aws.amazon.com

Attachment Content-Type Size
v1-0001-Replace-placeholders-with-known-strings.patch application/octet-stream 4.9 KB
v1-0001-Make-require_auth-error-message-similar-to-surrou.patch application/octet-stream 1020 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-04-21 04:31:01 Re: Make message strings in fe-connect.c consistent
Previous Message Ashutosh Bapat 2023-04-21 04:27:26 Re: New committers: Nathan Bossart, Amit Langote, Masahiko Sawada