Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 91c5a8c

Browse files
committed
Add errhint_plural() function and make use of it
Similar to existing errmsg_plural() and errdetail_plural(). Some errhint() calls hadn't received the proper plural treatment yet.
1 parent 287d2a9 commit 91c5a8c

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

doc/src/sgml/sources.sgml

+8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ ereport(ERROR,
282282
<function>errmsg</function>.
283283
</para>
284284
</listitem>
285+
<listitem>
286+
<para>
287+
<function>errhint_plural(const char *fmt_singular, const char *fmt_plural,
288+
unsigned long n, ...)</function> is like <function>errhint</function>, but with
289+
support for various plural forms of the message.
290+
For more information see <xref linkend="nls-guidelines"/>.
291+
</para>
292+
</listitem>
285293
<listitem>
286294
<para>
287295
<function>errcontext(const char *msg, ...)</function> is not normally called

src/backend/parser/parse_func.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
417417
func_signature_string(funcname, nargs,
418418
argnames,
419419
actual_arg_types)),
420-
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
421-
NameListToString(funcname),
422-
catDirectArgs, numDirectArgs),
420+
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
421+
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
422+
catDirectArgs,
423+
NameListToString(funcname),
424+
catDirectArgs, numDirectArgs),
423425
parser_errposition(pstate, location)));
424426
}
425427
else
@@ -446,9 +448,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
446448
func_signature_string(funcname, nargs,
447449
argnames,
448450
actual_arg_types)),
449-
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
450-
NameListToString(funcname),
451-
catDirectArgs, numDirectArgs),
451+
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
452+
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
453+
catDirectArgs,
454+
NameListToString(funcname),
455+
catDirectArgs, numDirectArgs),
452456
parser_errposition(pstate, location)));
453457
}
454458
else
@@ -485,9 +489,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
485489
func_signature_string(funcname, nargs,
486490
argnames,
487491
actual_arg_types)),
488-
errhint("There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
489-
NameListToString(funcname),
490-
catDirectArgs),
492+
errhint_plural("There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
493+
"There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
494+
catDirectArgs,
495+
NameListToString(funcname),
496+
catDirectArgs),
491497
parser_errposition(pstate, location)));
492498
}
493499
}

src/backend/utils/error/elog.c

+23
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,29 @@ errhint(const char *fmt,...)
11661166
}
11671167

11681168

1169+
/*
1170+
* errhint_plural --- add a hint error message text to the current error,
1171+
* with support for pluralization of the message text
1172+
*/
1173+
int
1174+
errhint_plural(const char *fmt_singular, const char *fmt_plural,
1175+
unsigned long n,...)
1176+
{
1177+
ErrorData *edata = &errordata[errordata_stack_depth];
1178+
MemoryContext oldcontext;
1179+
1180+
recursion_depth++;
1181+
CHECK_STACK_DEPTH();
1182+
oldcontext = MemoryContextSwitchTo(edata->assoc_context);
1183+
1184+
EVALUATE_MESSAGE_PLURAL(edata->domain, hint, false);
1185+
1186+
MemoryContextSwitchTo(oldcontext);
1187+
recursion_depth--;
1188+
return 0; /* return value does not matter */
1189+
}
1190+
1191+
11691192
/*
11701193
* errcontext_msg --- add a context error message text to the current error
11711194
*

src/include/utils/elog.h

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ extern int errdetail_plural(const char *fmt_singular, const char *fmt_plural,
188188

189189
extern int errhint(const char *fmt,...) pg_attribute_printf(1, 2);
190190

191+
extern int errhint_plural(const char *fmt_singular, const char *fmt_plural,
192+
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
193+
191194
/*
192195
* errcontext() is typically called in error context callback functions, not
193196
* within an ereport() invocation. The callback function can be in a different

src/nls-global.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BACKEND_COMMON_GETTEXT_TRIGGERS = \
5757
$(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
5858
errmsg errmsg_plural:1,2 \
5959
errdetail errdetail_log errdetail_plural:1,2 \
60-
errhint \
60+
errhint errhint_plural:1,2 \
6161
errcontext \
6262
XactLockTableWait:4 \
6363
MultiXactIdWait:6 \
@@ -66,7 +66,7 @@ BACKEND_COMMON_GETTEXT_FLAGS = \
6666
$(FRONTEND_COMMON_GETTEXT_FLAGS) \
6767
errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
6868
errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
69-
errhint:1:c-format \
69+
errhint:1:c-format errhint_plural:1:c-format errhint_plural:2:c-format \
7070
errcontext:1:c-format
7171

7272
FRONTEND_COMMON_GETTEXT_FILES = $(top_srcdir)/src/common/logging.c

0 commit comments

Comments
 (0)