Re: Odd usage of errmsg_internal in bufmgr.c

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Odd usage of errmsg_internal in bufmgr.c
Date: 2026-02-12 01:26:00
Message-ID: 9583D8A8-ED95-4B38-A616-79A4A90689E0@anarazel.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On February 11, 2026 4:37:54 PM PST, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>Hi,
>
>The relevant code looks like this:
>```
> msg_one = _("invalid page in block %u of relation \"%s\””);
>
> ereport(elevel,
> errcode(ERRCODE_DATA_CORRUPTED),
> errmsg_internal(msg_one, first + first_off, rpath.str) :
>```
>
>Here, the string is first translated via _() and stored in msg_one, and then passed to errmsg_internal(). However, according to the header comment of errmsg_internal():
>```
>/*
>* errmsg_internal --- add a primary error message text to the current error
>*
>* This is exactly like errmsg() except that strings passed to errmsg_internal
>* are not translated, and are customarily left out of the
>* internationalization message dictionary. This should be used for "can't
>* happen" cases that are probably not worth spending translation effort on.
>* We also use this for certain cases where we *must* not try to translate
>* the message because the translation would fail and result in infinite
>* error recursion.
>*/
>int
>errmsg_internal(const char *fmt,...)
>```
>
>errmsg_internal() is explicitly intended for non-translatable, internal messages. Passing an already translated string to it feels inconsistent with its documented purpose.

I don't think it is - you want to translate just once. There are other places using that pattern.

>In bufmgr.c, these corruption-related messages are clearly user-facing, so it seems more appropriate to use errmsg() here instead of errmsg_internal(). If my understanding is correct, the attached patch fixes the usages in bufmgr.c.
>
>This patch doesn't affect runtime behavior, but it avoids confusion for future readers, and helps prevent similar misuse elsewhere.

You can't do that, because then the strings won't be recognized as translatable by the translation machinery. The arguments to functions that take to-be-translated strings (like errmsg(..., ) or _(...) have to constants, so the strings can be extracted to then be translated.

Greetings,

Andres
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-02-12 01:34:50 Re: Odd usage of errmsg_internal in bufmgr.c
Previous Message Tatsuo Ishii 2026-02-12 01:17:01 Re: Row pattern recognition