Odd usage of errmsg_internal in bufmgr.c - Mailing list pgsql-hackers

From Chao Li
Subject Odd usage of errmsg_internal in bufmgr.c
Date
Msg-id 0C78B2B4-DBCF-4DA5-B999-EC1DA6459CB9@gmail.com
Whole thread Raw
Responses Re: Odd usage of errmsg_internal in bufmgr.c
Re: Odd usage of errmsg_internal in bufmgr.c
List 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,
accordingto 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
toit 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()
hereinstead 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
misuseelsewhere. 

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/





Attachment

pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: Speed up COPY FROM text/CSV parsing using SIMD
Next
From: wangpeng
Date:
Subject: Re: Fix wrong log in pgstat_report_checksum_failures_in_db()