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

Commit ed7ed76

Browse files
committed
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
1 parent 0886dde commit ed7ed76

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

doc/src/sgml/sources.sgml

+18-7
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,12 @@ ereport(ERROR,
214214
</listitem>
215215
<listitem>
216216
<para>
217-
<function>errdetail_log(const char *msg, ...)</function> is the same as
218-
<function>errdetail</> except that this string goes only to the server
219-
log, never to the client. If both <function>errdetail</> and
220-
<function>errdetail_log</> are used then one string goes to the client
221-
and the other to the log. This is useful for error details that are
222-
too security-sensitive or too bulky to include in the report
223-
sent to the client.
217+
<function>errdetail_internal(const char *msg, ...)</function> is the same
218+
as <function>errdetail</>, except that the message string will not be
219+
translated nor included in the internationalization message dictionary.
220+
This should be used for detail messages that are not worth expending
221+
translation effort on, for instance because they are too technical to be
222+
useful to most users.
224223
</para>
225224
</listitem>
226225
<listitem>
@@ -231,6 +230,18 @@ ereport(ERROR,
231230
For more information see <xref linkend="nls-guidelines">.
232231
</para>
233232
</listitem>
233+
<listitem>
234+
<para>
235+
<function>errdetail_log(const char *msg, ...)</function> is the same as
236+
<function>errdetail</> except that this string goes only to the server
237+
log, never to the client. If both <function>errdetail</> (or one of
238+
its equivalents above) and
239+
<function>errdetail_log</> are used then one string goes to the client
240+
and the other to the log. This is useful for error details that are
241+
too security-sensitive or too bulky to include in the report
242+
sent to the client.
243+
</para>
244+
</listitem>
234245
<listitem>
235246
<para>
236247
<function>errhint(const char *msg, ...)</function> supplies an optional

src/backend/utils/error/elog.c

+27
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,33 @@ errdetail(const char *fmt,...)
842842
}
843843

844844

845+
/*
846+
* errdetail_internal --- add a detail error message text to the current error
847+
*
848+
* This is exactly like errdetail() except that strings passed to
849+
* errdetail_internal are not translated, and are customarily left out of the
850+
* internationalization message dictionary. This should be used for detail
851+
* messages that seem not worth translating for one reason or another
852+
* (typically, that they don't seem to be useful to average users).
853+
*/
854+
int
855+
errdetail_internal(const char *fmt,...)
856+
{
857+
ErrorData *edata = &errordata[errordata_stack_depth];
858+
MemoryContext oldcontext;
859+
860+
recursion_depth++;
861+
CHECK_STACK_DEPTH();
862+
oldcontext = MemoryContextSwitchTo(ErrorContext);
863+
864+
EVALUATE_MESSAGE(detail, false, false);
865+
866+
MemoryContextSwitchTo(oldcontext);
867+
recursion_depth--;
868+
return 0; /* return value does not matter */
869+
}
870+
871+
845872
/*
846873
* errdetail_log --- add a detail_log error message text to the current error
847874
*/

src/include/utils/elog.h

+6
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ errdetail(const char *fmt,...)
146146
the supplied arguments. */
147147
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
148148

149+
extern int
150+
errdetail_internal(const char *fmt,...)
151+
/* This extension allows gcc to check the format string for consistency with
152+
the supplied arguments. */
153+
__attribute__((format(PG_PRINTF_ATTRIBUTE, 1, 2)));
154+
149155
extern int
150156
errdetail_log(const char *fmt,...)
151157
/* This extension allows gcc to check the format string for consistency with

0 commit comments

Comments
 (0)