0003-libpq-Improve-unknown-keyword-message-for-pg_service.patch

application/x-patch

Filename: 0003-libpq-Improve-unknown-keyword-message-for-pg_service.patch
Type: application/x-patch
Part: 2
Message: Re: Thoughts on a "global" client configuration?

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0003
Subject: libpq: Improve unknown-keyword message for pg_service.conf
File+
src/interfaces/libpq/fe-connect.c 2 1
src/interfaces/libpq/t/006_service.pl 19 0
From 20276a07bc1b7befa8c594ea2751f6497f18b70a Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Tue, 7 Oct 2025 15:07:51 -0700
Subject: [PATCH 3/6] libpq: Improve unknown-keyword message for
 pg_service.conf

Being told there's a syntax error in a file is a bit confusing if the
real problem is that the option name wasn't recognized.
---
 src/interfaces/libpq/fe-connect.c     |  3 ++-
 src/interfaces/libpq/t/006_service.pl | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index a3d12931fff..204f15787c9 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -6153,7 +6153,8 @@ parseServiceFile(const char *serviceFile,
 				if (!found_keyword)
 				{
 					libpq_append_error(errorMessage,
-									   "syntax error in service file \"%s\", line %d",
+									   "unknown keyword \"%s\" in service file \"%s\", line %d",
+									   key,
 									   serviceFile,
 									   linenr);
 					result = 3;
diff --git a/src/interfaces/libpq/t/006_service.pl b/src/interfaces/libpq/t/006_service.pl
index 9c692739511..6c1e7ec34ec 100644
--- a/src/interfaces/libpq/t/006_service.pl
+++ b/src/interfaces/libpq/t/006_service.pl
@@ -57,6 +57,14 @@ copy($srvfile_valid, $srvfile_nested)
   or die "Could not copy $srvfile_valid to $srvfile_nested: $!";
 append_to_file($srvfile_nested, "service=invalid_srv\n");
 
+# File with an unknown setting.
+my $srvfile_bad_keyword = "$td/pg_service_bad_keyword.conf";
+append_to_file(
+	$srvfile_bad_keyword, qq{
+[my_srv]
+bad-unknown-setting=1
+});
+
 # Service file with nested "servicefile" defined.
 my $srvfile_nested_2 = "$td/pg_service_nested_2.conf";
 copy($srvfile_valid, $srvfile_nested_2)
@@ -182,6 +190,17 @@ local $ENV{PGSERVICEFILE} = "$srvfile_empty";
 	);
 }
 
+# Check behavior with unknown keywords.
+{
+	local $ENV{PGSERVICEFILE} = $srvfile_bad_keyword;
+
+	$dummy_node->connect_fails(
+		'service=my_srv',
+		'connection with unknown connection option in service',
+		expected_stderr =>
+		  qr/unknown keyword "bad-unknown-setting" in service file/);
+}
+
 # Properly escape backslashes in the path, to ensure the generation of
 # correct connection strings.
 my $srvfile_win_cared = $srvfile_valid;
-- 
2.34.1