summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorPeter Eisentraut2021-03-31 07:15:51 +0000
committerPeter Eisentraut2021-03-31 07:16:25 +0000
commit91c5a8caaa61055959aa5fb68a00e5f690e39a34 (patch)
tree57749510770bcb337e191e0053a69248ef7ad917 /src/backend
parent287d2a97c1de07486e4525c8ad06258f04bd6268 (diff)
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.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/parser/parse_func.c24
-rw-r--r--src/backend/utils/error/elog.c23
2 files changed, 38 insertions, 9 deletions
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index debef1d14fb..baac089d689 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -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)));
}
}
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index e729ebece7b..9e4ea1b345a 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -1167,6 +1167,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
*
* Unlike other cases, multiple calls are allowed to build up a stack of