pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: Justin Pryzby <pryzby@telsasoft.com>
Subject: Re: Internal error codes triggered by regression tests and user queries, take 2
Date: Sat, 17 Oct 2026 14:00:00 +0300
Message-ID: <f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com> (raw)
In-Reply-To: <arJdH4WF14EXwWmt@paquier.xyz>
References: <94ac928b-8370-4db5-ada5-579a9ebc089d@gmail.com>
	<697477.1787754418@sss.pgh.pa.us>
	<mosliefjrclrikqpsasjy5ibzowba6vwk4ygimouikiht2i5pb@5g562jqflxsz>
	<73eb724a-c1a3-456c-be12-0375d4556b67@gmail.com>
	<apUcBVyazHEW5pcg@paquier.xyz>
	<91a1b0ab-2c6c-4471-b7a4-ee8ee8aed64e@gmail.com>
	<126103.1788721678@sss.pgh.pa.us>
	<8343126e-11e5-48df-9f96-ea03a2b7d5ba@gmail.com>
	<7a9b3652-134c-4565-82ad-839035a3a382@gmail.com>
	<arJdH4WF14EXwWmt@paquier.xyz>

Hello Michael and Tom,

22.09.2026 13:49, Michael Paquier wrote:
> As a whole, that looks OK, so applied on HEAD.  I did not look at
> 0002.

Let me share the following set of other internal errors:
1)
CREATE TABLE t AS SELECT ''::text a;
CREATE INDEX brinidx ON t USING brin
   (a text_bloom_ops(n_distinct_per_range = -1.0));

ERROR:  XX000: the bloom filter is too large (44629 > 8144)
LOCATION:  bloom_init, brin_bloom.c:
-> ERRCODE_PROGRAM_LIMIT_EXCEEDED

2)
SELECT pg_identify_object_as_address('1'::regclass, 1, 1);

ERROR:  XX000: unsupported object class: 1
LOCATION:  getObjectTypeDescription, objectaddress.c:4731
-> ERRCODE_INVALID_PARAMETER_VALUE

3)
SELECT pg_get_acl('1'::regclass, 1, 0);

ERROR:  XX000: unrecognized class ID: 1
LOCATION:  get_object_property_data, objectaddress.c:2821
-> ERRCODE_INVALID_PARAMETER_VALUE

4)
SELECT jsonb_to_tsvector('{}', '[{}]'::jsonb);

ERROR:  XX000: unexpected end of flag array
LOCATION:  parse_jsonb_index_flags, jsonfuncs.c:5614
-> ERRCODE_INVALID_PARAMETER_VALUE

5)
CREATE PROCEDURE p(INOUT a integer) LANGUAGE sql
   AS 'SELECT 1 WHERE false;';
CALL p(1);

ERROR:  XX000: procedure returned null record
LOCATION:  ExecuteCallStmt, functioncmds.c:2351
-> ERRCODE_INVALID_OBJECT_DEFINITION

6)
CREATE EXTENSION dblink;
CREATE FUNCTION connection_parameters() RETURNS text LANGUAGE SQL AS
   $f$ SELECT $$dbname='$$||current_database()||$$' port=$$||current_setting('port'); $f$;
SELECT dblink_connect('myconn',connection_parameters());
SELECT * FROM dblink_send_query('myconn', 'SELECT 1');
SELECT * FROM dblink('myconn', 'SELECT 2') AS t(i int);

ERROR:  XX000: could not send query: another command is already in progress
LOCATION:  storeQueryResult, dblink.c:1103
-> ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE

Please look at the attached patch which defines these error codes.

Best regards,
Alexander

Attachments:

  [text/x-patch] Define-missing-errcodes-2.patch (3.4K, ../f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com/3-Define-missing-errcodes-2.patch)
  download | inline diff:
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 9613f881985..29c19e0017f 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -1105,7 +1105,9 @@ storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
 	PGresult   *res;
 
 	if (!PQsendQuery(conn, sql))
-		elog(ERROR, "could not send query: %s", pchomp(PQerrorMessage(conn)));
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("could not send query: %s", pchomp(PQerrorMessage(conn)))));
 
 	if (!PQsetSingleRowMode(conn))	/* shouldn't fail */
 		elog(ERROR, "failed to set single-row mode for dblink query");
diff --git a/src/backend/access/brin/brin_bloom.c b/src/backend/access/brin/brin_bloom.c
index 5558a2edea5..788d89bbe82 100644
--- a/src/backend/access/brin/brin_bloom.c
+++ b/src/backend/access/brin/brin_bloom.c
@@ -342,8 +342,10 @@ bloom_init(int ndistinct, double false_positive_rate)
 	 * filters that are small individually, but too large when combined.
 	 */
 	if (nbytes > BloomMaxFilterSize)
-		elog(ERROR, "the bloom filter is too large (%d > %zu)", nbytes,
-			 BloomMaxFilterSize);
+		ereport(ERROR,
+				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+				 errmsg("the bloom filter is too large (%d > %zu)", nbytes,
+						BloomMaxFilterSize)));
 
 	/*
 	 * We allocate the whole filter. Most of it is going to be 0 bits, so the
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 09c9c751133..75aa4b9e714 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2819,7 +2819,8 @@ get_object_property_data(Oid class_id)
 	}
 
 	ereport(ERROR,
-			(errmsg_internal("unrecognized class ID: %u", class_id)));
+			(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+			 errmsg("unrecognized class ID: %u", class_id)));
 
 	return NULL;				/* keep MSC compiler happy */
 }
@@ -4728,7 +4729,9 @@ getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
 			break;
 
 		default:
-			elog(ERROR, "unsupported object class: %u", object->classId);
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+					 errmsg("unsupported object class: %u", object->classId)));
 	}
 
 	/* the result can never be empty */
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4d46013d7de..1f4c0b156b0 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -2348,7 +2348,9 @@ ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver
 		TupleTableSlot *slot;
 
 		if (fcinfo->isnull)
-			elog(ERROR, "procedure returned null record");
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+					 errmsg("procedure returned null record")));
 
 		/*
 		 * Ensure there's an active snapshot whilst we execute whatever's
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index adbafd0ecd3..4e4424f98d7 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -5611,7 +5611,9 @@ parse_jsonb_index_flags(Jsonb *jb)
 
 	/* expect end of array now */
 	if (type != WJB_END_ARRAY)
-		elog(ERROR, "unexpected end of flag array");
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				 errmsg("unexpected end of flag array")));
 
 	/* get final WJB_DONE and free iterator */
 	type = JsonbIteratorNext(&it, &v, false);


view thread (11+ messages)

Message-ID: <f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com>
Permalink:  ../f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com/
Also on:    postgresql.org/message-id/f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com

 ·  · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: exclusion@gmail.com, michael@paquier.xyz, tgl@sss.pgh.pa.us, andres@anarazel.de, pryzby@telsasoft.com
  Subject: Re: Internal error codes triggered by regression tests and user queries, take 2
  In-Reply-To: <f2758799-b7c1-4baf-8593-8899802cf48c@gmail.com>

* 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