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.
This commit is contained in:
Peter Eisentraut 2021-03-31 09:15:51 +02:00
parent 287d2a97c1
commit 91c5a8caaa
5 changed files with 51 additions and 11 deletions

View File

@ -282,6 +282,14 @@ ereport(ERROR,
<function>errmsg</function>.
</para>
</listitem>
<listitem>
<para>
<function>errhint_plural(const char *fmt_singular, const char *fmt_plural,
unsigned long n, ...)</function> is like <function>errhint</function>, but with
support for various plural forms of the message.
For more information see <xref linkend="nls-guidelines"/>.
</para>
</listitem>
<listitem>
<para>
<function>errcontext(const char *msg, ...)</function> is not normally called

View File

@ -417,9 +417,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
NameListToString(funcname),
catDirectArgs, numDirectArgs),
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
catDirectArgs,
NameListToString(funcname),
catDirectArgs, numDirectArgs),
parser_errposition(pstate, location)));
}
else
@ -446,9 +448,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
errhint("There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
NameListToString(funcname),
catDirectArgs, numDirectArgs),
errhint_plural("There is an ordered-set aggregate %s, but it requires %d direct argument, not %d.",
"There is an ordered-set aggregate %s, but it requires %d direct arguments, not %d.",
catDirectArgs,
NameListToString(funcname),
catDirectArgs, numDirectArgs),
parser_errposition(pstate, location)));
}
else
@ -485,9 +489,11 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
func_signature_string(funcname, nargs,
argnames,
actual_arg_types)),
errhint("There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
NameListToString(funcname),
catDirectArgs),
errhint_plural("There is an ordered-set aggregate %s, but it requires at least %d direct argument.",
"There is an ordered-set aggregate %s, but it requires at least %d direct arguments.",
catDirectArgs,
NameListToString(funcname),
catDirectArgs),
parser_errposition(pstate, location)));
}
}

View File

@ -1166,6 +1166,29 @@ errhint(const char *fmt,...)
}
/*
* errhint_plural --- add a hint error message text to the current error,
* with support for pluralization of the message text
*/
int
errhint_plural(const char *fmt_singular, const char *fmt_plural,
unsigned long n,...)
{
ErrorData *edata = &errordata[errordata_stack_depth];
MemoryContext oldcontext;
recursion_depth++;
CHECK_STACK_DEPTH();
oldcontext = MemoryContextSwitchTo(edata->assoc_context);
EVALUATE_MESSAGE_PLURAL(edata->domain, hint, false);
MemoryContextSwitchTo(oldcontext);
recursion_depth--;
return 0; /* return value does not matter */
}
/*
* errcontext_msg --- add a context error message text to the current error
*

View File

@ -188,6 +188,9 @@ extern int errdetail_plural(const char *fmt_singular, const char *fmt_plural,
extern int errhint(const char *fmt,...) pg_attribute_printf(1, 2);
extern int errhint_plural(const char *fmt_singular, const char *fmt_plural,
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
/*
* errcontext() is typically called in error context callback functions, not
* within an ereport() invocation. The callback function can be in a different

View File

@ -57,7 +57,7 @@ BACKEND_COMMON_GETTEXT_TRIGGERS = \
$(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
errmsg errmsg_plural:1,2 \
errdetail errdetail_log errdetail_plural:1,2 \
errhint \
errhint errhint_plural:1,2 \
errcontext \
XactLockTableWait:4 \
MultiXactIdWait:6 \
@ -66,7 +66,7 @@ BACKEND_COMMON_GETTEXT_FLAGS = \
$(FRONTEND_COMMON_GETTEXT_FLAGS) \
errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
errhint:1:c-format \
errhint:1:c-format errhint_plural:1:c-format errhint_plural:2:c-format \
errcontext:1:c-format
FRONTEND_COMMON_GETTEXT_FILES = $(top_srcdir)/src/common/logging.c