34#define LOG_SERVER_ONLY 16
36#define COMMERROR LOG_SERVER_ONLY
50#define WARNING_CLIENT_ONLY 20
67#define PGSIXBIT(ch) (((ch) - '0') & 0x3F)
68#define PGUNSIXBIT(val) (((val) & 0x3F) + '0')
70#define MAKE_SQLSTATE(ch1,ch2,ch3,ch4,ch5) \
71 (PGSIXBIT(ch1) + (PGSIXBIT(ch2) << 6) + (PGSIXBIT(ch3) << 12) + \
72 (PGSIXBIT(ch4) << 18) + (PGSIXBIT(ch5) << 24))
75#define ERRCODE_TO_CATEGORY(ec) ((ec) & ((1 << 12) - 1))
76#define ERRCODE_IS_CATEGORY(ec) (((ec) & ~((1 << 12) - 1)) == 0)
79#include "utils/errcodes.h"
90#if defined(errno) && defined(__linux__)
91#define pg_prevent_errno_in_scope() int __errno_location pg_attribute_unused()
92#elif defined(errno) && (defined(__darwin__) || defined(__FreeBSD__))
93#define pg_prevent_errno_in_scope() int __error pg_attribute_unused()
95#define pg_prevent_errno_in_scope()
140#ifdef HAVE__BUILTIN_CONSTANT_P
141#define ereport_domain(elevel, domain, ...) \
143 pg_prevent_errno_in_scope(); \
144 if (__builtin_constant_p(elevel) && (elevel) >= ERROR ? \
145 errstart_cold(elevel, domain) : \
146 errstart(elevel, domain)) \
147 __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
148 if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
152#define ereport_domain(elevel, domain, ...) \
154 const int elevel_ = (elevel); \
155 pg_prevent_errno_in_scope(); \
156 if (errstart(elevel_, domain)) \
157 __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \
158 if (elevel_ >= ERROR) \
163#define ereport(elevel, ...) \
164 ereport_domain(elevel, TEXTDOMAIN, __VA_ARGS__)
166#define TEXTDOMAIN NULL
170extern bool errstart(
int elevel,
const char *domain);
182extern
int errmsg_plural(const
char *fmt_singular, const
char *fmt_plural,
191 const
char *fmt_plural,
194extern
int errdetail_plural(const
char *fmt_singular, const
char *fmt_plural,
199extern
int errhint_plural(const
char *fmt_singular, const
char *fmt_plural,
210#define errcontext set_errcontext_domain(TEXTDOMAIN), errcontext_msg
239#define elog(elevel, ...) \
240 ereport(elevel, errmsg_internal(__VA_ARGS__))
267#define errsave_domain(context, domain, ...) \
269 struct Node *context_ = (context); \
270 pg_prevent_errno_in_scope(); \
271 if (errsave_start(context_, domain)) \
272 __VA_ARGS__, errsave_finish(context_, __FILE__, __LINE__, __func__); \
275#define errsave(context, ...) \
276 errsave_domain(context, TEXTDOMAIN, __VA_ARGS__)
285#define ereturn_domain(context, dummy_value, domain, ...) \
287 errsave_domain(context, domain, __VA_ARGS__); \
288 return dummy_value; \
291#define ereturn(context, dummy_value, ...) \
292 ereturn_domain(context, dummy_value, TEXTDOMAIN, __VA_ARGS__)
387 sigjmp_buf *_save_exception_stack##__VA_ARGS__ = PG_exception_stack; \
388 ErrorContextCallback *_save_context_stack##__VA_ARGS__ = error_context_stack; \
389 sigjmp_buf _local_sigjmp_buf##__VA_ARGS__; \
390 bool _do_rethrow##__VA_ARGS__ = false; \
391 if (sigsetjmp(_local_sigjmp_buf##__VA_ARGS__, 0) == 0) \
393 PG_exception_stack = &_local_sigjmp_buf##__VA_ARGS__
395#define PG_CATCH(...) \
399 PG_exception_stack = _save_exception_stack##__VA_ARGS__; \
400 error_context_stack = _save_context_stack##__VA_ARGS__
402#define PG_FINALLY(...) \
405 _do_rethrow##__VA_ARGS__ = true; \
407 PG_exception_stack = _save_exception_stack##__VA_ARGS__; \
408 error_context_stack = _save_context_stack##__VA_ARGS__
410#define PG_END_TRY(...) \
412 if (_do_rethrow##__VA_ARGS__) \
414 PG_exception_stack = _save_exception_stack##__VA_ARGS__; \
415 error_context_stack = _save_context_stack##__VA_ARGS__; \
422#ifdef HAVE_PG_ATTRIBUTE_NORETURN
423#define PG_RE_THROW() \
426#define PG_RE_THROW() \
427 (pg_re_throw(), pg_unreachable())
507#define LOG_DESTINATION_STDERR 1
508#define LOG_DESTINATION_SYSLOG 2
509#define LOG_DESTINATION_EVENTLOG 4
510#define LOG_DESTINATION_CSVLOG 8
511#define LOG_DESTINATION_JSONLOG 16
#define pg_attribute_cold
#define pg_attribute_noreturn()
int getinternalerrposition(void)
int int int pg_attribute_printf(2, 4)
int int errhidestmt(bool hide_stmt)
PGDLLIMPORT int Log_error_verbosity
PGDLLIMPORT int Log_destination
struct ErrorData ErrorData
void(* emit_log_hook_type)(ErrorData *edata)
int errcode_for_socket_access(void)
bool errsave_start(struct Node *context, const char *domain)
int err_generic_string(int field, const char *str)
PGDLLIMPORT sigjmp_buf * PG_exception_stack
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
void errsave_finish(struct Node *context, const char *filename, int lineno, const char *funcname)
int errhint(const char *fmt,...) pg_attribute_printf(1
int internalerrquery(const char *query)
int internalerrposition(int cursorpos)
bool check_log_of_query(ErrorData *edata)
bool errstart(int elevel, const char *domain)
void EmitErrorReport(void)
int errdetail(const char *fmt,...) pg_attribute_printf(1
char * GetErrorContextStack(void)
void FreeErrorData(ErrorData *edata)
const char * error_severity(int elevel)
int errmsg(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
int errcode_for_file_access(void)
void pre_format_elog_string(int errnumber, const char *domain)
int int int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
void ReThrowError(ErrorData *edata) pg_attribute_noreturn()
char * get_formatted_start_time(void)
ErrorData * CopyErrorData(void)
PGDLLIMPORT char * Log_destination_string
void FlushErrorState(void)
void write_stderr(const char *fmt,...) pg_attribute_printf(1
PGDLLIMPORT emit_log_hook_type emit_log_hook
int errcontext_msg(const char *fmt,...) pg_attribute_printf(1
void ThrowErrorData(ErrorData *edata)
bool message_level_is_interesting(int elevel)
void write_pipe_chunks(char *data, int len, int dest)
int errhidecontext(bool hide_ctx)
int int int errdetail_log(const char *fmt,...) pg_attribute_printf(1
PGDLLIMPORT char * Log_line_prefix
void write_csvlog(ErrorData *edata)
pg_attribute_cold bool errstart_cold(int elevel, const char *domain)
void write_jsonlog(ErrorData *edata)
const char * get_backend_type_for_log(void)
int errcode(int sqlerrcode)
int int errhint_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
PGDLLIMPORT bool syslog_split_messages
PGDLLIMPORT ErrorContextCallback * error_context_stack
void pg_re_throw(void) pg_attribute_noreturn()
PGDLLIMPORT bool syslog_sequence_numbers
char struct ErrorContextCallback ErrorContextCallback
char * format_elog_string(const char *fmt,...) pg_attribute_printf(1
void log_status_format(StringInfo buf, const char *format, ErrorData *edata)
char * get_formatted_log_time(void)
bool in_error_recursion_trouble(void)
void errfinish(const char *filename, int lineno, const char *funcname)
int errposition(int cursorpos)
char * unpack_sql_state(int sql_state)
int int int int errdetail_log_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
int set_errcontext_domain(const char *domain)
void reset_formatted_start_time(void)
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...) pg_attribute_printf(1
static void const char * fmt
struct ErrorContextCallback * previous
struct MemoryContextData * assoc_context
const char * context_domain
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)