From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: In libpq, always append new error messages to conn->errorMessage
Date: Mon, 11 Jan 2021 18:12:19 +0000
Message-ID: <E1kz1fv-00063r-7Q@gemulon.postgresql.org> (raw)
In libpq, always append new error messages to conn->errorMessage.
Previously, we had an undisciplined mish-mash of printfPQExpBuffer and
appendPQExpBuffer calls to report errors within libpq. This commit
establishes a uniform rule that appendPQExpBuffer[Str] should be used.
conn->errorMessage is reset only at the start of an application request,
and then accumulates messages till we're done. We can remove no less
than three different ad-hoc mechanisms that were used to get the effect
of concatenation of error messages within a sequence of operations.
Although this makes things quite a bit cleaner conceptually, the main
reason to do it is to make the world safer for the multiple-target-host
feature that was added awhile back. Previously, there were many cases
in which an error occurring during an individual host connection attempt
would wipe out the record of what had happened during previous attempts.
(The reporting is still inadequate, in that it can be hard to tell which
host got the failure, but that seems like a matter for a separate commit.)
Currently, lo_import and lo_export contain exceptions to the "never
use printfPQExpBuffer" rule. If we changed them, we'd risk reporting
an incidental lo_close failure before the actual read or write
failure, which would be confusing, not least because lo_close happened
after the main failure. We could improve this by inventing an
internal version of lo_close that doesn't reset the errorMessage; but
we'd also need a version of PQfn() that does that, and it didn't quite
seem worth the trouble for now.
Discussion: https://postgr.es/m/BN6PR05MB3492948E4FD76C156E747E8BC9160@BN6PR05MB3492.namprd05.prod.outlook.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ffa2e4670123124b92f037d335a1e844c3782d3f
Modified Files
--------------
src/interfaces/libpq/fe-auth-scram.c | 124 ++++++------
src/interfaces/libpq/fe-auth.c | 169 ++++++++--------
src/interfaces/libpq/fe-connect.c | 317 +++++++++++++------------------
src/interfaces/libpq/fe-exec.c | 281 ++++++++++++---------------
src/interfaces/libpq/fe-gssapi-common.c | 9 +-
src/interfaces/libpq/fe-lobj.c | 210 ++++++++++----------
src/interfaces/libpq/fe-misc.c | 54 +++---
src/interfaces/libpq/fe-protocol2.c | 36 ++--
src/interfaces/libpq/fe-protocol3.c | 51 +++--
src/interfaces/libpq/fe-secure-common.c | 24 +--
src/interfaces/libpq/fe-secure-gssapi.c | 28 +--
src/interfaces/libpq/fe-secure-openssl.c | 124 ++++++------
src/interfaces/libpq/fe-secure.c | 28 +--
src/interfaces/libpq/libpq-int.h | 18 +-
14 files changed, 699 insertions(+), 774 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: In libpq, always append new error messages to conn->errorMessage
In-Reply-To: <E1kz1fv-00063r-7Q@gemulon.postgresql.org>
References: <E1kz1fv-00063r-7Q@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox