From ed7ed76712263717477487d326d3e86cfb0ad31c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 16 Jul 2011 13:41:48 -0400 Subject: [PATCH] Add an errdetail_internal() ereport auxiliary routine. This function supports untranslated detail messages, in the same way that errmsg_internal supports untranslated primary messages. We've needed this for some time IMO, but discussion of some cases in the SSI code provided the impetus to actually add it. Kevin Grittner, with minor adjustments by me --- doc/src/sgml/sources.sgml | 25 ++++++++++++++++++------- src/backend/utils/error/elog.c | 27 +++++++++++++++++++++++++++ src/include/utils/elog.h | 6 ++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/sources.sgml b/doc/src/sgml/sources.sgml index ac8f462de0..4ed83d6189 100644 --- a/doc/src/sgml/sources.sgml +++ b/doc/src/sgml/sources.sgml @@ -214,13 +214,12 @@ ereport(ERROR, - errdetail_log(const char *msg, ...) is the same as - errdetail except that this string goes only to the server - log, never to the client. If both errdetail and - errdetail_log are used then one string goes to the client - and the other to the log. This is useful for error details that are - too security-sensitive or too bulky to include in the report - sent to the client. + errdetail_internal(const char *msg, ...) is the same + as errdetail, except that the message string will not be + translated nor included in the internationalization message dictionary. + This should be used for detail messages that are not worth expending + translation effort on, for instance because they are too technical to be + useful to most users. @@ -231,6 +230,18 @@ ereport(ERROR, For more information see . + + + errdetail_log(const char *msg, ...) is the same as + errdetail except that this string goes only to the server + log, never to the client. If both errdetail (or one of + its equivalents above) and + errdetail_log are used then one string goes to the client + and the other to the log. This is useful for error details that are + too security-sensitive or too bulky to include in the report + sent to the client. + + errhint(const char *msg, ...) supplies an optional diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 337b875fe2..7c7927509b 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -842,6 +842,33 @@ errdetail(const char *fmt,...) } +/* + * errdetail_internal --- add a detail error message text to the current error + * + * This is exactly like errdetail() except that strings passed to + * errdetail_internal are not translated, and are customarily left out of the + * internationalization message dictionary. This should be used for detail + * messages that seem not worth translating for one reason or another + * (typically, that they don't seem to be useful to average users). + */ +int +errdetail_internal(const char *fmt,...) +{ + ErrorData *edata = &errordata[errordata_stack_depth]; + MemoryContext oldcontext; + + recursion_depth++; + CHECK_STACK_DEPTH(); + oldcontext = MemoryContextSwitchTo(ErrorContext); + + EVALUATE_MESSAGE(detail, false, false); + + MemoryContextSwitchTo(oldcontext); + recursion_depth--; + return 0; /* return value does not matter */ +} + + /* * errdetail_log --- add a detail_log error message text to the current error */ diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index 4a3bd02689..93b141d683 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -146,6 +146,12 @@ errdetail(const char *fmt,...) the supplied arguments. */ __attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); +extern int +errdetail_internal(const char *fmt,...) +/* This extension allows gcc to check the format string for consistency with + the supplied arguments. */ +__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2))); + extern int errdetail_log(const char *fmt,...) /* This extension allows gcc to check the format string for consistency with