Skip to content

Commit 3864df0

Browse files
Chao Li (Evan)hackorum
authored andcommitted
elog: document style guidelines for error message functions
Add brief style guidelines to the header comments of errmsg(), errdetail(), errhint(), errcontext() and elog. The styles are described in: * https://www.postgresql.org/docs/current/error-style-guide.html * https://www.postgresql.org/docs/devel/error-message-reporting.html Author: Chao Li <lic@highgo.com>
1 parent b597835 commit 3864df0

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/backend/utils/error/elog.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,9 @@ errcode_for_socket_access(void)
10871087
* In addition to the usual %-escapes recognized by printf, "%m" in
10881088
* fmt is replaced by the error message for the caller's value of errno.
10891089
*
1090+
* Style guidelines: do not capitalize the first letter, and do not end
1091+
* the message with a period or other punctuation.
1092+
*
10901093
* Note: no newline is needed at the end of the fmt string, since
10911094
* ereport will provide one for the output methods that need it.
10921095
*/
@@ -1390,6 +1393,11 @@ errmsg_plural(const char *fmt_singular, const char *fmt_plural,
13901393

13911394
/*
13921395
* errdetail --- add a detail error message text to the current error
1396+
*
1397+
* Style guidelines: use complete sentences; capitalize the first word
1398+
* of each sentence, and end each with a period; put two spaces after
1399+
* a period if another sentence follows (for English text; may be
1400+
* inappropriate in other languages).
13931401
*/
13941402
int
13951403
errdetail(const char *fmt, ...)
@@ -1504,6 +1512,11 @@ errdetail_plural(const char *fmt_singular, const char *fmt_plural,
15041512

15051513
/*
15061514
* errhint --- add a hint error message text to the current error
1515+
*
1516+
* Style guidelines: use complete sentences; capitalize the first word
1517+
* of each sentence, and end each with a period; put two spaces after
1518+
* a period if another sentence follows (for English text; may be
1519+
* inappropriate in other languages).
15071520
*/
15081521
int
15091522
errhint(const char *fmt, ...)

src/include/utils/elog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ extern int errhint_plural(const char *fmt_singular, const char *fmt_plural,
210210
* is not usually the correct domain for translating the context message.
211211
* set_errcontext_domain() first sets the domain to be used, and
212212
* errcontext_msg() passes the actual message.
213+
*
214+
* Style guidelines: do not capitalize the first letter, do not end the string
215+
* with a period, and avoid complete sentences.
213216
*/
214217
#define errcontext set_errcontext_domain(TEXTDOMAIN), errcontext_msg
215218

@@ -237,6 +240,11 @@ extern int getinternalerrposition(void);
237240
/*----------
238241
* Old-style error reporting API: to be used in this way:
239242
* elog(ERROR, "portal \"%s\" not found", stmt->portalname);
243+
*
244+
* elog() is intended for internal errors and low-level debug logging.
245+
* It always uses a default SQLSTATE, and the message is not translated.
246+
* Messages that may be of interest to end users should use ereport()
247+
* instead.
240248
*----------
241249
*/
242250
#define elog(elevel, ...) \

0 commit comments

Comments
 (0)