From 67460682d046605c4a654b9b00fc1502d6615e1a Mon Sep 17 00:00:00 2001
From: Sami Imseih <samimseih@gmail.com>
Date: Fri, 3 Jul 2026 10:51:08 -0500
Subject: [PATCH v2 2/3] Make error messages in pgstat_register_kind()
 consistent

Use the same errmsg format across all validation checks, including
the statistics name and kind ID where available.
---
 src/backend/utils/activity/pgstat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index f6223d2a3dd..2d8b92c4051 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -1511,11 +1511,11 @@ pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
 
 	if (kind_info->name == NULL || strlen(kind_info->name) == 0)
 		ereport(ERROR,
-				(errmsg("custom cumulative statistics name is invalid"),
+				(errmsg("failed to register custom cumulative statistics with ID %u", kind),
 				 errhint("Provide a non-empty name for the custom cumulative statistics.")));
 
 	if (!pgstat_is_kind_custom(kind))
-		ereport(ERROR, (errmsg("custom cumulative statistics ID %u is out of range", kind),
+		ereport(ERROR, (errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
 						errhint("Provide a custom cumulative statistics ID between %u and %u.",
 								PGSTAT_KIND_CUSTOM_MIN, PGSTAT_KIND_CUSTOM_MAX)));
 
@@ -1531,7 +1531,7 @@ pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
 	{
 		if (kind_info->shared_size == 0)
 			ereport(ERROR,
-					(errmsg("custom cumulative statistics property is invalid"),
+					(errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
 					 errhint("Custom cumulative statistics require a shared memory size for fixed-numbered objects.")));
 		if (kind_info->init_shmem_cb == NULL)
 			ereport(ERROR,
@@ -1550,7 +1550,7 @@ pgstat_register_kind(PgStat_Kind kind, const PgStat_KindInfo *kind_info)
 							 "snapshot_cb")));
 		if (kind_info->track_entry_count)
 			ereport(ERROR,
-					(errmsg("custom cumulative statistics property is invalid"),
+					(errmsg("failed to register custom cumulative statistics \"%s\" with ID %u", kind_info->name, kind),
 					 errhint("Custom cumulative statistics cannot use entry count tracking for fixed-numbered objects.")));
 	}
 	else
-- 
2.50.1 (Apple Git-155)

