Skip to content

Commit 4244cf6

Browse files
committed
Add errhint_internal()
We have errmsg_internal(), errdetail_internal(), but not errhint_internal(). Sometimes it is useful to output a hint with already translated format string (e.g. because there different messages depending on the condition). For message/detail we do that with the _internal() variants, but we can't do that with hint today. It's possible to work around that that by using something like str = psprintf(translated_format, args); ereport(... errhint("%s", str); but that's not exactly pretty and makes it harder to avoid memory leaks. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/ym3dqpa4xcvoeknewcw63x77vnqdosbqcetjinb2zfoh65k55m@m4ozmwhr6lk6
1 parent 49b8252 commit 4244cf6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/backend/utils/error/elog.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,27 @@ errhint(const char *fmt,...)
13301330
return 0; /* return value does not matter */
13311331
}
13321332

1333+
/*
1334+
* errhint_internal --- add a hint error message text to the current error
1335+
*
1336+
* Non-translated version of errhint(), see also errmsg_internal().
1337+
*/
1338+
int
1339+
errhint_internal(const char *fmt,...)
1340+
{
1341+
ErrorData *edata = &errordata[errordata_stack_depth];
1342+
MemoryContext oldcontext;
1343+
1344+
recursion_depth++;
1345+
CHECK_STACK_DEPTH();
1346+
oldcontext = MemoryContextSwitchTo(edata->assoc_context);
1347+
1348+
EVALUATE_MESSAGE(edata->domain, hint, false, false);
1349+
1350+
MemoryContextSwitchTo(oldcontext);
1351+
recursion_depth--;
1352+
return 0; /* return value does not matter */
1353+
}
13331354

13341355
/*
13351356
* errhint_plural --- add a hint error message text to the current error,

src/include/utils/elog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ extern int errdetail_plural(const char *fmt_singular, const char *fmt_plural,
195195
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);
196196

197197
extern int errhint(const char *fmt,...) pg_attribute_printf(1, 2);
198+
extern int errhint_internal(const char *fmt,...) pg_attribute_printf(1, 2);
198199

199200
extern int errhint_plural(const char *fmt_singular, const char *fmt_plural,
200201
unsigned long n,...) pg_attribute_printf(1, 4) pg_attribute_printf(2, 4);

0 commit comments

Comments
 (0)