I think we need to do something slightly earlier than that. Attached is
what I propose.

I agree, my patch could miss one case with undefined $$stderr.
Fixed my patch with your suggestion

I think the short answer is no, we've already hijacked STDOUT/STDERR in
Utils.pm to point to the log file, and you shouldn't mess with them. I
don't think you're using SimpleTee correctly anyway, but it's really not
meant for general use, only for the use in Utils.pm.

Thanks for the info!

Regards, Oleg Tselebrovskiy
diff --git a/src/test/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build
index 9c50de7efb0..4c183ac1e9c 100644
--- a/src/test/modules/test_misc/meson.build
+++ b/src/test/modules/test_misc/meson.build
@@ -16,6 +16,7 @@ tests += {
       't/005_timeouts.pl',
       't/006_signal_autovacuum.pl',
       't/007_catcache_inval.pl',
+      't/008_node_psql_on_error_die.pl',
     ],
   },
 }
diff --git a/src/test/modules/test_misc/t/008_node_psql_on_error_die.pl b/src/test/modules/test_misc/t/008_node_psql_on_error_die.pl
new file mode 100644
index 00000000000..654797fd636
--- /dev/null
+++ b/src/test/modules/test_misc/t/008_node_psql_on_error_die.pl
@@ -0,0 +1,30 @@
+
+# Copyright (c) 2025, PostgreSQL Global Development Group
+
+# Tests that check that calling node->psql with on_error_die => 1 and without
+# passing $stderr will result in intuitive exception
+
+use strict;
+use warnings FATAL => 'all';
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+$node->start;
+
+eval
+{
+	$node->psql('postgres', q{SELEC 1}, on_error_die => 1);
+};
+
+if ($@)
+{
+	print $@;
+	like($@, qr/<not collected>/, "Expected <not collected>");
+	unlike($@, qr/Use of uninitialized value in concatenation/,
+			   "This is a 'warnings FATAL' output, we don't want this");
+}
+
+done_testing();
\ No newline at end of file
diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 1c11750ac1d..3afb7c40e91 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -2199,6 +2199,14 @@ sub psql
 			$ret = $?;
 		};
 		my $exc_save = $@;
+
+		# we need a dummy $stderr from hereon, if we didn't collect it
+		if (!defined $stderr)
+		{
+			my $errtxt = "<not collected>";
+			$stderr = \$errtxt;
+		}
+
 		if ($exc_save)
 		{
 

Reply via email to