1
/*-------------------------------------------------------------------------
4
* POSTGRES error reporting/logging definitions.
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
10
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.78 2004-12-31 22:03:46 pgsql Exp $
12
*-------------------------------------------------------------------------
19
/* Error level codes */
20
#define DEBUG5 10 /* Debugging messages, in categories of
21
* decreasing detail. */
25
#define DEBUG1 14 /* used by GUC debug_* variables */
26
#define LOG 15 /* Server operational messages; sent only
27
* to server log by default. */
28
#define COMMERROR 16 /* Client communication problems; same as
29
* LOG for server reporting, but never
31
#define INFO 17 /* Informative messages that are always
32
* sent to client; is not affected by
33
* client_min_messages */
34
#define NOTICE 18 /* Helpful messages to users about query
35
* operation; sent to client and server
37
#define WARNING 19 /* Warnings. NOTICE is for expected
38
* messages like implicit sequence
39
* creation by SERIAL. WARNING is for
40
* unexpected messages. */
41
#define ERROR 20 /* user error - abort transaction; return
43
/* Save ERROR value in PGERROR so it can be restored when Win32 includes
44
* modify it. We have to use a constant rather than ERROR because macros
45
* are expanded only when referenced outside macros.
50
#define FATAL 21 /* fatal error - abort process */
51
#define PANIC 22 /* take down the other backends with me */
53
/* #define DEBUG DEBUG1 */ /* Backward compatibility with pre-7.3 */
56
/* macros for representing SQLSTATE strings compactly */
57
#define PGSIXBIT(ch) (((ch) - '0') & 0x3F)
58
#define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
60
#define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) \
61
(PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
62
(PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
64
/* These macros depend on the fact that '0' becomes a zero in SIXBIT */
65
#define ERRCODE_TO_CATEGORY(ec) ((ec) & ((1 << 12) - 1))
66
#define ERRCODE_IS_CATEGORY(ec) (((ec) & ~((1 << 12) - 1)) == 0)
68
/* SQLSTATE codes for errors are defined in a separate file */
69
#include "utils/errcodes.h"
72
/* Which __func__ symbol do we have, if any? */
73
#ifdef HAVE_FUNCNAME__FUNC
74
#define PG_FUNCNAME_MACRO __func__
76
#ifdef HAVE_FUNCNAME__FUNCTION
77
#define PG_FUNCNAME_MACRO __FUNCTION__
79
#define PG_FUNCNAME_MACRO NULL
85
* New-style error reporting API: to be used in this way:
87
* (errcode(ERRCODE_UNDEFINED_CURSOR),
88
* errmsg("portal \"%s\" not found", stmt->portalname),
89
* ... other errxxx() fields as needed ...));
91
* The error level is required, and so is a primary error message (errmsg
92
* or errmsg_internal). All else is optional. errcode() defaults to
93
* ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
94
* if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
98
#define ereport(elevel, rest) \
99
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
100
(errfinish rest) : (void) 0)
102
extern bool errstart(int elevel, const char *filename, int lineno,
103
const char *funcname);
104
extern void errfinish(int dummy,...);
106
extern int errcode(int sqlerrcode);
108
extern int errcode_for_file_access(void);
109
extern int errcode_for_socket_access(void);
112
errmsg(const char *fmt,...)
113
/* This extension allows gcc to check the format string for consistency with
114
the supplied arguments. */
115
__attribute__((format(printf, 1, 2)));
118
errmsg_internal(const char *fmt,...)
119
/* This extension allows gcc to check the format string for consistency with
120
the supplied arguments. */
121
__attribute__((format(printf, 1, 2)));
124
errdetail(const char *fmt,...)
125
/* This extension allows gcc to check the format string for consistency with
126
the supplied arguments. */
127
__attribute__((format(printf, 1, 2)));
130
errhint(const char *fmt,...)
131
/* This extension allows gcc to check the format string for consistency with
132
the supplied arguments. */
133
__attribute__((format(printf, 1, 2)));
136
errcontext(const char *fmt,...)
137
/* This extension allows gcc to check the format string for consistency with
138
the supplied arguments. */
139
__attribute__((format(printf, 1, 2)));
141
extern int errfunction(const char *funcname);
142
extern int errposition(int cursorpos);
144
extern int internalerrposition(int cursorpos);
145
extern int internalerrquery(const char *query);
147
extern int geterrposition(void);
148
extern int getinternalerrposition(void);
152
* Old-style error reporting API: to be used in this way:
153
* elog(ERROR, "portal \"%s\" not found", stmt->portalname);
156
#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
158
extern void elog_start(const char *filename, int lineno, const char *funcname);
160
elog_finish(int elevel, const char *fmt,...)
161
/* This extension allows gcc to check the format string for consistency with
162
the supplied arguments. */
163
__attribute__((format(printf, 2, 3)));
166
/* Support for attaching context information to error reports */
168
typedef struct ErrorContextCallback
170
struct ErrorContextCallback *previous;
171
void (*callback) (void *arg);
173
} ErrorContextCallback;
175
extern DLLIMPORT ErrorContextCallback *error_context_stack;
179
* API for catching ereport(ERROR) exits. Use these macros like so:
183
* ... code that might throw ereport(ERROR) ...
187
* ... error recovery code ...
191
* (The braces are not actually necessary, but are recommended so that
192
* pg_indent will indent the construct nicely.) The error recovery code
193
* can optionally do PG_RE_THROW() to propagate the same error outwards.
195
* Note: while the system will correctly propagate any new ereport(ERROR)
196
* occurring in the recovery section, there is a small limit on the number
197
* of levels this will work for. It's best to keep the error recovery
198
* section simple enough that it can't generate any new errors, at least
199
* not before popping the error stack.
204
sigjmp_buf *save_exception_stack = PG_exception_stack; \
205
ErrorContextCallback *save_context_stack = error_context_stack; \
206
sigjmp_buf local_sigjmp_buf; \
207
if (sigsetjmp(local_sigjmp_buf, 0) == 0) \
209
PG_exception_stack = &local_sigjmp_buf
215
PG_exception_stack = save_exception_stack; \
216
error_context_stack = save_context_stack
218
#define PG_END_TRY() \
220
PG_exception_stack = save_exception_stack; \
221
error_context_stack = save_context_stack; \
224
#define PG_RE_THROW() \
225
siglongjmp(*PG_exception_stack, 1)
227
extern DLLIMPORT sigjmp_buf *PG_exception_stack;
230
/* Stuff that error handlers might want to use */
233
* ErrorData holds the data accumulated during any one ereport() cycle.
234
* Any non-NULL pointers must point to palloc'd data.
235
* (The const pointers are an exception; we assume they point at non-freeable
238
typedef struct ErrorData
240
int elevel; /* error level */
241
bool output_to_server; /* will report to server log? */
242
bool output_to_client; /* will report to client? */
243
bool show_funcname; /* true to force funcname inclusion */
244
const char *filename; /* __FILE__ of ereport() call */
245
int lineno; /* __LINE__ of ereport() call */
246
const char *funcname; /* __func__ of ereport() call */
247
int sqlerrcode; /* encoded ERRSTATE */
248
char *message; /* primary error message */
249
char *detail; /* detail error message */
250
char *hint; /* hint message */
251
char *context; /* context message */
252
int cursorpos; /* cursor index into query string */
253
int internalpos; /* cursor index into internalquery */
254
char *internalquery; /* text of internally-generated query */
255
int saved_errno; /* errno at entry */
258
extern void EmitErrorReport(void);
259
extern ErrorData *CopyErrorData(void);
260
extern void FreeErrorData(ErrorData *edata);
261
extern void FlushErrorState(void);
262
extern void ReThrowError(ErrorData *edata);
265
/* GUC-configurable parameters */
269
PGERROR_TERSE, /* single-line error messages */
270
PGERROR_DEFAULT, /* recommended style */
271
PGERROR_VERBOSE /* all the facts, ma'am */
274
extern PGErrorVerbosity Log_error_verbosity;
275
extern char *Log_line_prefix;
276
extern int Log_destination;
278
/* Log destination bitmap */
279
#define LOG_DESTINATION_STDERR 1
280
#define LOG_DESTINATION_SYSLOG 2
281
#define LOG_DESTINATION_EVENTLOG 4
283
/* Other exported functions */
284
extern void DebugFileOpen(void);
287
* Write errors to stderr (or by equal means when stderr is
288
* not available). Used before ereport/elog can be used
289
* safely (memory context, GUC load etc)
292
write_stderr(const char *fmt,...)
293
/* This extension allows gcc to check the format string for consistency with
294
the supplied arguments. */
295
__attribute__((format(printf, 1, 2)));