[PATCH] libpq: Wrap out-of-memory error messages with libpq_gettext()

Started by Joshua Shanks11 months ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t52623
psql -h localhost -U postgres

Built from patchset v1 (message #1), September 20, 2026 at 02:31 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t52623_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t52623_1 && git checkout t52623_1

Patchset v1 (message #1) is on t52623_1

Jump to latest
#1Joshua Shanks
jjshanks@gmail.com

Hi,

The recent patch for passwordFromFile() error handling highlighted
that many other out-of-memory error messages in libpq still aren't
wrapped with libpq_gettext().

Attached is a patch that systematically wraps the remaining bare "out
of memory" strings across libpq with libpq_gettext() to ensure consistent
translation support. This covers:
- Authentication modules (fe-auth.c, fe-auth-scram.c, fe-auth-oauth.c)
- Connection handling (fe-connect.c, fe-cancel.c)
- Protocol and secure communication (fe-protocol3.c, fe-secure-*.c)
- Other modules (fe-exec.c, fe-lobj.c, fe-gssapi-common.c)

Cheers,
Joshua

Attachments:

t52623_1
0001-libpq-Wrap-out-of-memory-error-messages-with-libpq_g.patchapplication/octet-stream; name=0001-libpq-Wrap-out-of-memory-error-messages-with-libpq_g.patchDownload+75-76
#2Fujii Masao
masao.fujii@gmail.com
In reply to: Joshua Shanks (#1)
Re: [PATCH] libpq: Wrap out-of-memory error messages with libpq_gettext()

On Sun, Nov 9, 2025 at 5:21 AM Joshua Shanks <jjshanks@gmail.com> wrote:

Hi,

The recent patch for passwordFromFile() error handling highlighted that many other out-of-memory error messages in libpq still aren't wrapped with libpq_gettext().

Attached is a patch that systematically wraps the remaining bare "out of memory" strings across libpq with libpq_gettext() to ensure consistent translation support. This covers:
- Authentication modules (fe-auth.c, fe-auth-scram.c, fe-auth-oauth.c)
- Connection handling (fe-connect.c, fe-cancel.c)
- Protocol and secure communication (fe-protocol3.c, fe-secure-*.c)
- Other modules (fe-exec.c, fe-lobj.c, fe-gssapi-common.c)

- libpq_append_conn_error(conn, "out of memory");
+ libpq_append_conn_error(conn, libpq_gettext("out of memory"));

Seems libpq_gettext() doesn't need to be called here,
since libpq_append_conn_error() already does that internally. No?

Regards,

--
Fujii Masao

#3Joshua Shanks
jjshanks@gmail.com
In reply to: Fujii Masao (#2)
Re: [PATCH] libpq: Wrap out-of-memory error messages with libpq_gettext()

You're absolutely right, thank you for catching that! I was
double-wrapping the translation.

libpq_append_conn_error() already calls libpq_gettext()
internally (fe-misc.c:1420), so these changes are unnecessary. I'm
withdrawing this patch.

On Sun, Nov 9, 2025 at 11:04 PM Fujii Masao <masao.fujii@gmail.com> wrote:

Show quoted text

On Sun, Nov 9, 2025 at 5:21 AM Joshua Shanks <jjshanks@gmail.com> wrote:

Hi,

The recent patch for passwordFromFile() error handling highlighted that

many other out-of-memory error messages in libpq still aren't wrapped with
libpq_gettext().

Attached is a patch that systematically wraps the remaining bare "out of

memory" strings across libpq with libpq_gettext() to ensure consistent
translation support. This covers:

- Authentication modules (fe-auth.c, fe-auth-scram.c, fe-auth-oauth.c)
- Connection handling (fe-connect.c, fe-cancel.c)
- Protocol and secure communication (fe-protocol3.c, fe-secure-*.c)
- Other modules (fe-exec.c, fe-lobj.c, fe-gssapi-common.c)

- libpq_append_conn_error(conn, "out of memory");
+ libpq_append_conn_error(conn, libpq_gettext("out of memory"));

Seems libpq_gettext() doesn't need to be called here,
since libpq_append_conn_error() already does that internally. No?

Regards,

--
Fujii Masao

#4Michael Paquier
michael@paquier.xyz
In reply to: Joshua Shanks (#3)
Re: [PATCH] libpq: Wrap out-of-memory error messages with libpq_gettext()

On Mon, Nov 10, 2025 at 05:21:00PM -0800, Joshua Shanks wrote:

You're absolutely right, thank you for catching that! I was
double-wrapping the translation.

libpq_append_conn_error() already calls libpq_gettext()
internally (fe-misc.c:1420), so these changes are unnecessary. I'm
withdrawing this patch.

Following a bit here, as I'm sure that this thread comes from
861af9261035.

The reason behind the additions of the two libpq_gettext() in
passwordFromFile(), as done in 861af9261035, is just to provide a
safety net in case we introduce a new caller of passwordFromFile()
that forgets to apply gettext(), with for example a new message
printed to stderr. Not mandatory for these two new cases as
libpq_append_conn_error() is called shortly after grabbing the error
message grabbed for the current caller of passwordFromFile(), still
better to have in the long-run, IMO. That's also the style we've
adopted for the error messages related to the protocol or fe-exec.c.
--
Michael