]> granicus.if.org Git - postgresql/blobdiff - src/include/utils/elog.h
Improve the recently-added support for properly pluralized error messages
[postgresql] / src / include / utils / elog.h
index f226f772911a04b024b82de54742ee381c19b2e7..81ddb9fc3779fc142de58e1d135fde132d1dadeb 100644 (file)
@@ -4,10 +4,10 @@
  *       POSTGRES error reporting/logging definitions.
  *
  *
- * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.79 2005/06/10 16:23:10 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.100 2009/06/04 18:33:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #define DEBUG3         12
 #define DEBUG2         13
 #define DEBUG1         14                      /* used by GUC debug_* variables */
-#define LOG                    15                      /* Server operational messages; sent only
-                                                                * to server log by default. */
-#define COMMERROR      16                      /* Client communication problems; same as
-                                                                * LOG for server reporting, but never
-                                                                * sent to client. */
-#define INFO           17                      /* Informative messages that are always
-                                                                * sent to client;      is not affected by
-                                                                * client_min_messages */
+#define LOG                    15                      /* Server operational messages; sent only to
+                                                                * server log by default. */
+#define COMMERROR      16                      /* Client communication problems; same as LOG
+                                                                * for server reporting, but never sent to
+                                                                * client. */
+#define INFO           17                      /* Messages specifically requested by user
+                                                                * (eg VACUUM VERBOSE output); always sent to
+                                                                * client regardless of client_min_messages,
+                                                                * but by default not sent to server log. */
 #define NOTICE         18                      /* Helpful messages to users about query
-                                                                * operation;  sent to client and server
-                                                                * log by default. */
-#define WARNING                19                      /* Warnings.  NOTICE is for expected
-                                                                * messages like implicit sequence
-                                                                * creation by SERIAL. WARNING is for
-                                                                * unexpected messages. */
-#define ERROR          20                      /* user error - abort transaction; return
-                                                                * to known state */
+                                                                * operation; sent to client and server log
+                                                                * by default. */
+#define WARNING                19                      /* Warnings.  NOTICE is for expected messages
+                                                                * like implicit sequence creation by SERIAL.
+                                                                * WARNING is for unexpected messages. */
+#define ERROR          20                      /* user error - abort transaction; return to
+                                                                * known state */
 /* Save ERROR value in PGERROR so it can be restored when Win32 includes
  * modify it.  We have to use a constant rather than ERROR because macros
  * are expanded only when referenced outside macros.
  * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
  * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
  * NOTICE or below.
+ *
+ * ereport_domain() allows a message domain to be specified, for modules that
+ * wish to use a different message catalog from the backend's. To avoid having
+ * one copy of the default text domain per .o file, we define it as NULL here
+ * and have errstart insert the default text domain.  Modules can either use
+ * ereport_domain() directly, or preferably they can override the TEXTDOMAIN
+ * macro.
  *----------
  */
-#define ereport(elevel, rest)  \
-       (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
+#define ereport_domain(elevel, domain, rest)   \
+       (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
         (errfinish rest) : (void) 0)
 
+#define ereport(elevel, rest)  \
+       ereport_domain(elevel, TEXTDOMAIN, rest)
+
+#define TEXTDOMAIN NULL
+
 extern bool errstart(int elevel, const char *filename, int lineno,
-                const char *funcname);
+                const char *funcname, const char *domain);
 extern void errfinish(int dummy,...);
 
 extern int     errcode(int sqlerrcode);
@@ -120,12 +132,34 @@ errmsg_internal(const char *fmt,...)
    the supplied arguments. */
 __attribute__((format(printf, 1, 2)));
 
+extern int
+errmsg_plural(const char *fmt_singular, const char *fmt_plural,
+                         unsigned long n, ...)
+/* This extension allows gcc to check the format string for consistency with
+   the supplied arguments. */
+__attribute__((format(printf, 1, 4)))
+__attribute__((format(printf, 2, 4)));
+
 extern int
 errdetail(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
    the supplied arguments. */
 __attribute__((format(printf, 1, 2)));
 
+extern int
+errdetail_log(const char *fmt,...)
+/* This extension allows gcc to check the format string for consistency with
+   the supplied arguments. */
+__attribute__((format(printf, 1, 2)));
+
+extern int
+errdetail_plural(const char *fmt_singular, const char *fmt_plural,
+                                unsigned long n, ...)
+/* This extension allows gcc to check the format string for consistency with
+   the supplied arguments. */
+__attribute__((format(printf, 1, 4)))
+__attribute__((format(printf, 2, 4)));
+
 extern int
 errhint(const char *fmt,...)
 /* This extension allows gcc to check the format string for consistency with
@@ -138,12 +172,15 @@ errcontext(const char *fmt,...)
    the supplied arguments. */
 __attribute__((format(printf, 1, 2)));
 
+extern int     errhidestmt(bool hide_stmt);
+
 extern int     errfunction(const char *funcname);
 extern int     errposition(int cursorpos);
 
 extern int     internalerrposition(int cursorpos);
 extern int     internalerrquery(const char *query);
 
+extern int     geterrcode(void);
 extern int     geterrposition(void);
 extern int     getinternalerrposition(void);
 
@@ -172,7 +209,7 @@ typedef struct ErrorContextCallback
        void       *arg;
 } ErrorContextCallback;
 
-extern DLLIMPORT ErrorContextCallback *error_context_stack;
+extern PGDLLIMPORT ErrorContextCallback *error_context_stack;
 
 
 /*----------
@@ -197,6 +234,13 @@ extern DLLIMPORT ErrorContextCallback *error_context_stack;
  * of levels this will work for.  It's best to keep the error recovery
  * section simple enough that it can't generate any new errors, at least
  * not before popping the error stack.
+ *
+ * Note: an ereport(FATAL) will not be caught by this construct; control will
+ * exit straight through proc_exit().  Therefore, do NOT put any cleanup
+ * of non-process-local resources into the error recovery section, at least
+ * not without taking thought for what will happen during ereport(FATAL).
+ * The PG_ENSURE_ERROR_CLEANUP macros provided by storage/ipc.h may be
+ * helpful in such cases.
  *----------
  */
 #define PG_TRY()  \
@@ -221,10 +265,19 @@ extern DLLIMPORT ErrorContextCallback *error_context_stack;
                error_context_stack = save_context_stack; \
        } while (0)
 
+/*
+ * gcc understands __attribute__((noreturn)); for other compilers, insert
+ * a useless exit() call so that the compiler gets the point.
+ */
+#ifdef __GNUC__
+#define PG_RE_THROW()  \
+       pg_re_throw()
+#else
 #define PG_RE_THROW()  \
-       siglongjmp(*PG_exception_stack, 1)
+       (pg_re_throw(), exit(1))
+#endif
 
-extern DLLIMPORT sigjmp_buf *PG_exception_stack;
+extern PGDLLIMPORT sigjmp_buf *PG_exception_stack;
 
 
 /* Stuff that error handlers might want to use */
@@ -241,12 +294,15 @@ typedef struct ErrorData
        bool            output_to_server;               /* will report to server log? */
        bool            output_to_client;               /* will report to client? */
        bool            show_funcname;  /* true to force funcname inclusion */
+       bool            hide_stmt;              /* true to prevent STATEMENT: inclusion */
        const char *filename;           /* __FILE__ of ereport() call */
        int                     lineno;                 /* __LINE__ of ereport() call */
        const char *funcname;           /* __func__ of ereport() call */
+       const char *domain;                     /* message domain */
        int                     sqlerrcode;             /* encoded ERRSTATE */
        char       *message;            /* primary error message */
        char       *detail;                     /* detail error message */
+       char       *detail_log;         /* detail error message for server log only */
        char       *hint;                       /* hint message */
        char       *context;            /* context message */
        int                     cursorpos;              /* cursor index into query string */
@@ -260,6 +316,7 @@ extern ErrorData *CopyErrorData(void);
 extern void FreeErrorData(ErrorData *edata);
 extern void FlushErrorState(void);
 extern void ReThrowError(ErrorData *edata);
+extern void pg_re_throw(void) __attribute__((noreturn));
 
 
 /* GUC-configurable parameters */
@@ -271,7 +328,7 @@ typedef enum
        PGERROR_VERBOSE                         /* all the facts, ma'am */
 } PGErrorVerbosity;
 
-extern PGErrorVerbosity Log_error_verbosity;
+extern int     Log_error_verbosity;
 extern char *Log_line_prefix;
 extern int     Log_destination;
 
@@ -279,10 +336,16 @@ extern int        Log_destination;
 #define LOG_DESTINATION_STDERR  1
 #define LOG_DESTINATION_SYSLOG  2
 #define LOG_DESTINATION_EVENTLOG 4
+#define LOG_DESTINATION_CSVLOG  8
 
 /* Other exported functions */
 extern void DebugFileOpen(void);
 extern char *unpack_sql_state(int sql_state);
+extern bool in_error_recursion_trouble(void);
+
+#ifdef HAVE_SYSLOG
+extern void set_syslog_parameters(const char *ident, int facility);
+#endif
 
 /*
  * Write errors to stderr (or by equal means when stderr is