error handling in pqRowProcessor broken

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: error handling in pqRowProcessor broken
Date: 2022-04-19 14:34:36
Message-ID: b52277b9-fa66-b027-4a37-fb8989c73ff8@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The error handling for pqRowProcessor is described as

* Add the received row to the current async result (conn->result).
* Returns 1 if OK, 0 if error occurred.
*
* On error, *errmsgp can be set to an error string to be returned.
* If it is left NULL, the error is presumed to be "out of memory".

I find that this doesn't work anymore. If you set *errmsgp = "some
message" and return 0, then psql will just print a result set with zero
rows.

Bisecting points to

commit 618c16707a6d6e8f5c83ede2092975e4670201ad
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Date: Fri Feb 18 15:35:15 2022 -0500

Rearrange libpq's error reporting to avoid duplicated error text.

It is very uncommon to get an error from pqRowProcessor(). To
reproduce, I inserted this code:

diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index c7c48d07dc..9c1b33c6e2 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -1124,6 +1124,12 @@ pqRowProcessor(PGconn *conn, const char **errmsgp)
return 0;
}

+ if (nfields == 7)
+ {
+ *errmsgp = "gotcha";
+ goto fail;
+ }
+
/*
* Basically we just allocate space in the PGresult for each field and
* copy the data over.

This will produce assorted failures in the regression tests that
illustrate the effect.

(Even before the above commit, the handling of the returned message was
a bit weird: The error output was just the message string, without any
prefix like "ERROR:".)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-04-19 14:36:36 Re: TRAP: FailedAssertion("HaveRegisteredOrActiveSnapshot()", File: "toast_internals.c", Line: 670, PID: 19403)
Previous Message Daniel Gustafsson 2022-04-19 14:27:57 Re: Add version and data directory to initdb output