| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Odd usage of errmsg_internal in bufmgr.c |
| Date: | 2026-02-12 00:37:54 |
| Message-ID: | 0C78B2B4-DBCF-4DA5-B999-EC1DA6459CB9@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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.
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.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-bufmgr-Fix-wrong-usage-of-errmsg_internal-in-buff.patch | application/octet-stream | 3.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | wangpeng | 2026-02-12 00:59:13 | Re: Fix wrong log in pgstat_report_checksum_failures_in_db() |
| Previous Message | Nathan Bossart | 2026-02-11 22:39:43 | Re: Speed up COPY FROM text/CSV parsing using SIMD |