Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdJVA-0008Rb-5Y for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2016 15:57:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bdJV9-00068f-Od for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Aug 2016 15:57:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdJV8-00065y-8s for pgsql-hackers@postgresql.org; Fri, 26 Aug 2016 15:57:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdJV5-0008JP-FN for pgsql-hackers@postgresql.org; Fri, 26 Aug 2016 15:57:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u7QFuuws027232; Fri, 26 Aug 2016 11:56:56 -0400 From: Tom Lane To: Robert Haas cc: Jakob Egger , "pgsql-hackers@postgresql.org" Subject: Re: PG_DIAG_SEVERITY and a possible bug in pq_parse_errornotice() In-reply-to: <23534.1472212411@sss.pgh.pa.us> References: <11859.1472139831@sss.pgh.pa.us> <15203.1472145555@sss.pgh.pa.us> <23534.1472212411@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 26 Aug 2016 07:53:31 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <27211.1472226975.0@sss.pgh.pa.us> Date: Fri, 26 Aug 2016 11:56:56 -0400 Message-ID: <27231.1472227016@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27211.1472226975.1@sss.pgh.pa.us> I wrote: > After sleeping on it, I think the right answer is to introduce the new > error-message field (and not worry about 9.5). Will work on a patch > for that, unless I hear objections pretty soon. So far as I can find, the attached is all we need to do to introduce a new message field. (This patch doesn't address the memory-context questions, but it does fix the localization-driven failure demonstrated upthread.) Any objections? Anyone want to bikeshed the field name? I considered PG_DIAG_SEVERITY_NONLOCALIZED and PG_DIAG_SEVERITY_ENGLISH before settling on PG_DIAG_SEVERITY_ASCII, but I can't say I'm in love with that. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="add-nonlocalized-error-severity.patch"; charset="us-ascii" Content-ID: <27211.1472226975.2@sss.pgh.pa.us> Content-Description: add-nonlocalized-error-severity.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index f22e3da..40ae0ff 100644 *** a/doc/src/sgml/libpq.sgml --- b/doc/src/sgml/libpq.sgml *************** char *PQresultErrorField(const PGresult=20 *** 2767,2772 **** --- 2767,2788 ---- =20=20 + + PG_DIAG_SEVERITY_ASCII + + + The severity; the field contents are ERROR, + FATAL, or PANIC (in an error message), + or WARNING, NOTICE, DEBUG, + INFO, or LOG (in a notice message). + This is identical to the PG_DIAG_SEVERITY field ex= cept + that the contents are never localized. This is present only = in + reports generated by PostgreSQL versions 9.6 + and later. + + + +=20 PG_DIAG_SQLSTATE diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index 9c96d8f..9bddb19 100644 *** a/doc/src/sgml/protocol.sgml --- b/doc/src/sgml/protocol.sgml *************** message. *** 4884,4889 **** --- 4884,4908 ---- =20=20 + A + + + + Severity: the field contents are + ERROR, FATAL, or + PANIC (in an error message), or + WARNING, NOTICE, DEBUG, + INFO, or LOG (in a notice message). + This is identical to the S field except + that the contents are never localized. This is present only in + messages generated by PostgreSQL versions 9.6 + and later. + + + +=20 + + C diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c index 921242f..b04a7ef 100644 *** a/src/backend/libpq/pqmq.c --- b/src/backend/libpq/pqmq.c *************** pq_parse_errornotice(StringInfo msg, Err *** 237,246 **** switch (code) { case PG_DIAG_SEVERITY: if (strcmp(value, "DEBUG") =3D=3D 0) ! edata->elevel =3D DEBUG1; /* or some other DEBUG level */ else if (strcmp(value, "LOG") =3D=3D 0) ! edata->elevel =3D LOG; /* can't be COMMERROR */ else if (strcmp(value, "INFO") =3D=3D 0) edata->elevel =3D INFO; else if (strcmp(value, "NOTICE") =3D=3D 0) --- 237,262 ---- switch (code) { case PG_DIAG_SEVERITY: + /* ignore, trusting we'll get a nonlocalized version */ + break; + case PG_DIAG_SEVERITY_ASCII: if (strcmp(value, "DEBUG") =3D=3D 0) ! { ! /* ! * We can't reconstruct the exact DEBUG level, but ! * presumably it was >=3D client_min_messages, so select ! * DEBUG1 to ensure we'll pass it on to the client. ! */ ! edata->elevel =3D DEBUG1; ! } else if (strcmp(value, "LOG") =3D=3D 0) ! { ! /* ! * It can't be LOG_SERVER_ONLY, or the worker wouldn't ! * have sent it to us; so LOG is the correct value. ! */ ! edata->elevel =3D LOG; ! } else if (strcmp(value, "INFO") =3D=3D 0) edata->elevel =3D INFO; else if (strcmp(value, "NOTICE") =3D=3D 0) *************** pq_parse_errornotice(StringInfo msg, Err *** 254,264 **** else if (strcmp(value, "PANIC") =3D=3D 0) edata->elevel =3D PANIC; else ! elog(ERROR, "unknown error severity"); break; case PG_DIAG_SQLSTATE: if (strlen(value) !=3D 5) ! elog(ERROR, "malformed sql state"); edata->sqlerrcode =3D MAKE_SQLSTATE(value[0], value[1], value[2], value[3], value[4]); break; --- 270,280 ---- else if (strcmp(value, "PANIC") =3D=3D 0) edata->elevel =3D PANIC; else ! elog(ERROR, "unrecognized error severity: \"%s\"", value); break; case PG_DIAG_SQLSTATE: if (strlen(value) !=3D 5) ! elog(ERROR, "invalid SQLSTATE: \"%s\"", value); edata->sqlerrcode =3D MAKE_SQLSTATE(value[0], value[1], value[2], value[3], value[4]); break; *************** pq_parse_errornotice(StringInfo msg, Err *** 308,314 **** edata->funcname =3D pstrdup(value); break; default: ! elog(ERROR, "unknown error field: %d", (int) code); break; } } --- 324,330 ---- edata->funcname =3D pstrdup(value); break; default: ! elog(ERROR, "unrecognized error field code: %d", (int) code); break; } } diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 78d441d..ab71b50 100644 *** a/src/backend/utils/error/elog.c --- b/src/backend/utils/error/elog.c *************** write_csvlog(ErrorData *edata) *** 2744,2750 **** appendStringInfoChar(&buf, ','); =20=20 /* Error severity */ ! appendStringInfoString(&buf, error_severity(edata->elevel)); appendStringInfoChar(&buf, ','); =20=20 /* SQL state code */ --- 2744,2750 ---- appendStringInfoChar(&buf, ','); =20=20 /* Error severity */ ! appendStringInfoString(&buf, gettext(error_severity(edata->elevel))); appendStringInfoChar(&buf, ','); =20=20 /* SQL state code */ *************** send_message_to_server_log(ErrorData *ed *** 2861,2867 **** formatted_log_time[0] =3D '\0'; =20=20 log_line_prefix(&buf, edata); ! appendStringInfo(&buf, "%s: ", error_severity(edata->elevel)); =20=20 if (Log_error_verbosity >=3D PGERROR_VERBOSE) appendStringInfo(&buf, "%s: ", unpack_sql_state(edata->sqlerrcode)); --- 2861,2867 ---- formatted_log_time[0] =3D '\0'; =20=20 log_line_prefix(&buf, edata); ! appendStringInfo(&buf, "%s: ", gettext(error_severity(edata->elevel))); =20=20 if (Log_error_verbosity >=3D PGERROR_VERBOSE) appendStringInfo(&buf, "%s: ", unpack_sql_state(edata->sqlerrcode)); *************** send_message_to_frontend(ErrorData *edat *** 3144,3155 **** if (PG_PROTOCOL_MAJOR(FrontendProtocol) >=3D 3) { /* New style with separate fields */ char tbuf[12]; int ssval; int i; =20=20 pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY); ! err_sendstring(&msgbuf, error_severity(edata->elevel)); =20=20 /* unpack MAKE_SQLSTATE code */ ssval =3D edata->sqlerrcode; --- 3144,3159 ---- if (PG_PROTOCOL_MAJOR(FrontendProtocol) >=3D 3) { /* New style with separate fields */ + const char *sev; char tbuf[12]; int ssval; int i; =20=20 + sev =3D error_severity(edata->elevel); pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY); ! err_sendstring(&msgbuf, gettext(sev)); ! pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY_ASCII); ! err_sendstring(&msgbuf, sev); =20=20 /* unpack MAKE_SQLSTATE code */ ssval =3D edata->sqlerrcode; *************** send_message_to_frontend(ErrorData *edat *** 3268,3274 **** =20=20 initStringInfo(&buf); =20=20 ! appendStringInfo(&buf, "%s: ", error_severity(edata->elevel)); =20=20 if (edata->show_funcname && edata->funcname) appendStringInfo(&buf, "%s: ", edata->funcname); --- 3272,3278 ---- =20=20 initStringInfo(&buf); =20=20 ! appendStringInfo(&buf, "%s: ", gettext(error_severity(edata->elevel))); =20=20 if (edata->show_funcname && edata->funcname) appendStringInfo(&buf, "%s: ", edata->funcname); *************** get_errno_symbol(int errnum) *** 3578,3584 **** =20=20 =20=20 /* ! * error_severity --- get localized string representing elevel */ static const char * error_severity(int elevel) --- 3582,3591 ---- =20=20 =20=20 /* ! * error_severity --- get string representing elevel ! * ! * The string is not localized here, but we mark the strings for translat= ion ! * so that callers can invoke gettext on the result. */ static const char * error_severity(int elevel) *************** error_severity(int elevel) *** 3592,3620 **** case DEBUG3: case DEBUG4: case DEBUG5: ! prefix =3D _("DEBUG"); break; case LOG: case LOG_SERVER_ONLY: ! prefix =3D _("LOG"); break; case INFO: ! prefix =3D _("INFO"); break; case NOTICE: ! prefix =3D _("NOTICE"); break; case WARNING: ! prefix =3D _("WARNING"); break; case ERROR: ! prefix =3D _("ERROR"); break; case FATAL: ! prefix =3D _("FATAL"); break; case PANIC: ! prefix =3D _("PANIC"); break; default: prefix =3D "???"; --- 3599,3627 ---- case DEBUG3: case DEBUG4: case DEBUG5: ! prefix =3D gettext_noop("DEBUG"); break; case LOG: case LOG_SERVER_ONLY: ! prefix =3D gettext_noop("LOG"); break; case INFO: ! prefix =3D gettext_noop("INFO"); break; case NOTICE: ! prefix =3D gettext_noop("NOTICE"); break; case WARNING: ! prefix =3D gettext_noop("WARNING"); break; case ERROR: ! prefix =3D gettext_noop("ERROR"); break; case FATAL: ! prefix =3D gettext_noop("FATAL"); break; case PANIC: ! prefix =3D gettext_noop("PANIC"); break; default: prefix =3D "???"; diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h index 74c344c..e318e18 100644 *** a/src/include/postgres_ext.h --- b/src/include/postgres_ext.h *************** typedef PG_INT64_TYPE pg_int64; *** 49,54 **** --- 49,55 ---- * applications. */ #define PG_DIAG_SEVERITY 'S' + #define PG_DIAG_SEVERITY_ASCII 'A' #define PG_DIAG_SQLSTATE 'C' #define PG_DIAG_MESSAGE_PRIMARY 'M' #define PG_DIAG_MESSAGE_DETAIL 'D' diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index d1b91c8..58c8cab 100644 *** a/src/interfaces/libpq/fe-exec.c --- b/src/interfaces/libpq/fe-exec.c *************** pqInternalNotice(const PGNoticeHooks *ho *** 824,829 **** --- 824,830 ---- */ pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, msgBuf); pqSaveMessageField(res, PG_DIAG_SEVERITY, libpq_gettext("NOTICE")); + pqSaveMessageField(res, PG_DIAG_SEVERITY_ASCII, "NOTICE"); /* XXX should provide a SQLSTATE too? */ =20=20 /* ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--