Commit fde03e8b authored by Peter Eisentraut's avatar Peter Eisentraut

Use croak instead of die in Perl code when appropriate

parent 32291aed
...@@ -7,6 +7,7 @@ package convutils; ...@@ -7,6 +7,7 @@ package convutils;
use strict; use strict;
use Carp;
use Exporter 'import'; use Exporter 'import';
our @EXPORT = our @EXPORT =
...@@ -698,7 +699,7 @@ sub make_charmap ...@@ -698,7 +699,7 @@ sub make_charmap
{ {
my ($out, $charset, $direction, $verbose) = @_; my ($out, $charset, $direction, $verbose) = @_;
die "unacceptable direction : $direction" croak "unacceptable direction : $direction"
if ($direction != TO_UNICODE && $direction != FROM_UNICODE); if ($direction != TO_UNICODE && $direction != FROM_UNICODE);
# In verbose mode, print a large comment with the source and comment of # In verbose mode, print a large comment with the source and comment of
...@@ -759,7 +760,7 @@ sub make_charmap_combined ...@@ -759,7 +760,7 @@ sub make_charmap_combined
{ {
my ($charset, $direction) = @_; my ($charset, $direction) = @_;
die "unacceptable direction : $direction" croak "unacceptable direction : $direction"
if ($direction != TO_UNICODE && $direction != FROM_UNICODE); if ($direction != TO_UNICODE && $direction != FROM_UNICODE);
my @combined; my @combined;
......
...@@ -35,6 +35,7 @@ package RewindTest; ...@@ -35,6 +35,7 @@ package RewindTest;
use strict; use strict;
use warnings; use warnings;
use Carp;
use Config; use Config;
use Exporter 'import'; use Exporter 'import';
use File::Copy; use File::Copy;
...@@ -228,7 +229,7 @@ sub run_pg_rewind ...@@ -228,7 +229,7 @@ sub run_pg_rewind
{ {
# Cannot come here normally # Cannot come here normally
die("Incorrect test mode specified"); croak("Incorrect test mode specified");
} }
# Now move back postgresql.conf with old settings # Now move back postgresql.conf with old settings
......
...@@ -82,6 +82,7 @@ package PostgresNode; ...@@ -82,6 +82,7 @@ package PostgresNode;
use strict; use strict;
use warnings; use warnings;
use Carp;
use Config; use Config;
use Cwd; use Cwd;
use Exporter 'import'; use Exporter 'import';
...@@ -359,7 +360,7 @@ sub set_replication_conf ...@@ -359,7 +360,7 @@ sub set_replication_conf
my $pgdata = $self->data_dir; my $pgdata = $self->data_dir;
$self->host eq $test_pghost $self->host eq $test_pghost
or die "set_replication_conf only works with the default host"; or croak "set_replication_conf only works with the default host";
open my $hba, '>>', "$pgdata/pg_hba.conf"; open my $hba, '>>', "$pgdata/pg_hba.conf";
print $hba "\n# Allow replication (set up by PostgresNode.pm)\n"; print $hba "\n# Allow replication (set up by PostgresNode.pm)\n";
...@@ -624,7 +625,7 @@ sub init_from_backup ...@@ -624,7 +625,7 @@ sub init_from_backup
print print
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n"; "# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
die "Backup \"$backup_name\" does not exist at $backup_path" croak "Backup \"$backup_name\" does not exist at $backup_path"
unless -d $backup_path; unless -d $backup_path;
mkdir $self->backup_dir; mkdir $self->backup_dir;
...@@ -1445,7 +1446,7 @@ sub lsn ...@@ -1445,7 +1446,7 @@ sub lsn
'replay' => 'pg_last_wal_replay_lsn()'); 'replay' => 'pg_last_wal_replay_lsn()');
$mode = '<undef>' if !defined($mode); $mode = '<undef>' if !defined($mode);
die "unknown mode for 'lsn': '$mode', valid modes are " croak "unknown mode for 'lsn': '$mode', valid modes are "
. join(', ', keys %modes) . join(', ', keys %modes)
if !defined($modes{$mode}); if !defined($modes{$mode});
...@@ -1490,7 +1491,7 @@ sub wait_for_catchup ...@@ -1490,7 +1491,7 @@ sub wait_for_catchup
$mode = defined($mode) ? $mode : 'replay'; $mode = defined($mode) ? $mode : 'replay';
my %valid_modes = my %valid_modes =
('sent' => 1, 'write' => 1, 'flush' => 1, 'replay' => 1); ('sent' => 1, 'write' => 1, 'flush' => 1, 'replay' => 1);
die "unknown mode $mode for 'wait_for_catchup', valid modes are " croak "unknown mode $mode for 'wait_for_catchup', valid modes are "
. join(', ', keys(%valid_modes)) . join(', ', keys(%valid_modes))
unless exists($valid_modes{$mode}); unless exists($valid_modes{$mode});
...@@ -1517,7 +1518,7 @@ sub wait_for_catchup ...@@ -1517,7 +1518,7 @@ sub wait_for_catchup
my $query = my $query =
qq[SELECT $lsn_expr <= ${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';]; qq[SELECT $lsn_expr <= ${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';];
$self->poll_query_until('postgres', $query) $self->poll_query_until('postgres', $query)
or die "timed out waiting for catchup"; or croak "timed out waiting for catchup";
print "done\n"; print "done\n";
} }
...@@ -1547,9 +1548,9 @@ sub wait_for_slot_catchup ...@@ -1547,9 +1548,9 @@ sub wait_for_slot_catchup
$mode = defined($mode) ? $mode : 'restart'; $mode = defined($mode) ? $mode : 'restart';
if (!($mode eq 'restart' || $mode eq 'confirmed_flush')) if (!($mode eq 'restart' || $mode eq 'confirmed_flush'))
{ {
die "valid modes are restart, confirmed_flush"; croak "valid modes are restart, confirmed_flush";
} }
die 'target lsn must be specified' unless defined($target_lsn); croak 'target lsn must be specified' unless defined($target_lsn);
print "Waiting for replication slot " print "Waiting for replication slot "
. $slot_name . "'s " . $slot_name . "'s "
. $mode . $mode
...@@ -1559,7 +1560,7 @@ sub wait_for_slot_catchup ...@@ -1559,7 +1560,7 @@ sub wait_for_slot_catchup
my $query = my $query =
qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name';]; qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name';];
$self->poll_query_until('postgres', $query) $self->poll_query_until('postgres', $query)
or die "timed out waiting for catchup"; or croak "timed out waiting for catchup";
print "done\n"; print "done\n";
} }
...@@ -1588,7 +1589,7 @@ null columns. ...@@ -1588,7 +1589,7 @@ null columns.
sub query_hash sub query_hash
{ {
my ($self, $dbname, $query, @columns) = @_; my ($self, $dbname, $query, @columns) = @_;
die 'calls in array context for multi-row results not supported yet' croak 'calls in array context for multi-row results not supported yet'
if (wantarray); if (wantarray);
# Replace __COLUMNS__ if found # Replace __COLUMNS__ if found
...@@ -1663,8 +1664,8 @@ sub pg_recvlogical_upto ...@@ -1663,8 +1664,8 @@ sub pg_recvlogical_upto
my $timeout_exception = 'pg_recvlogical timed out'; my $timeout_exception = 'pg_recvlogical timed out';
die 'slot name must be specified' unless defined($slot_name); croak 'slot name must be specified' unless defined($slot_name);
die 'endpos must be specified' unless defined($endpos); croak 'endpos must be specified' unless defined($endpos);
my @cmd = ( my @cmd = (
'pg_recvlogical', '-S', $slot_name, '--dbname', 'pg_recvlogical', '-S', $slot_name, '--dbname',
...@@ -1674,7 +1675,7 @@ sub pg_recvlogical_upto ...@@ -1674,7 +1675,7 @@ sub pg_recvlogical_upto
while (my ($k, $v) = each %plugin_options) while (my ($k, $v) = each %plugin_options)
{ {
die "= is not permitted to appear in replication option name" croak "= is not permitted to appear in replication option name"
if ($k =~ qr/=/); if ($k =~ qr/=/);
push @cmd, "-o", "$k=$v"; push @cmd, "-o", "$k=$v";
} }
......
...@@ -19,6 +19,7 @@ package RecursiveCopy; ...@@ -19,6 +19,7 @@ package RecursiveCopy;
use strict; use strict;
use warnings; use warnings;
use Carp;
use File::Basename; use File::Basename;
use File::Copy; use File::Copy;
...@@ -68,7 +69,7 @@ sub copypath ...@@ -68,7 +69,7 @@ sub copypath
if (defined $params{filterfn}) if (defined $params{filterfn})
{ {
die "if specified, filterfn must be a subroutine reference" croak "if specified, filterfn must be a subroutine reference"
unless defined(ref $params{filterfn}) unless defined(ref $params{filterfn})
and (ref $params{filterfn} eq 'CODE'); and (ref $params{filterfn} eq 'CODE');
...@@ -80,7 +81,7 @@ sub copypath ...@@ -80,7 +81,7 @@ sub copypath
} }
# Complain if original path is bogus, because _copypath_recurse won't. # Complain if original path is bogus, because _copypath_recurse won't.
die "\"$base_src_dir\" does not exist" if !-e $base_src_dir; croak "\"$base_src_dir\" does not exist" if !-e $base_src_dir;
# Start recursive copy from current directory # Start recursive copy from current directory
return _copypath_recurse($base_src_dir, $base_dest_dir, "", $filterfn); return _copypath_recurse($base_src_dir, $base_dest_dir, "", $filterfn);
...@@ -98,11 +99,11 @@ sub _copypath_recurse ...@@ -98,11 +99,11 @@ sub _copypath_recurse
# Check for symlink -- needed only on source dir # Check for symlink -- needed only on source dir
# (note: this will fall through quietly if file is already gone) # (note: this will fall through quietly if file is already gone)
die "Cannot operate on symlink \"$srcpath\"" if -l $srcpath; croak "Cannot operate on symlink \"$srcpath\"" if -l $srcpath;
# Abort if destination path already exists. Should we allow directories # Abort if destination path already exists. Should we allow directories
# to exist already? # to exist already?
die "Destination path \"$destpath\" already exists" if -e $destpath; croak "Destination path \"$destpath\" already exists" if -e $destpath;
# If this source path is a file, simply copy it to destination with the # If this source path is a file, simply copy it to destination with the
# same name and we're done. # same name and we're done.
...@@ -148,7 +149,7 @@ sub _copypath_recurse ...@@ -148,7 +149,7 @@ sub _copypath_recurse
return 1 if !-e $srcpath; return 1 if !-e $srcpath;
# Else it's some weird file type; complain. # Else it's some weird file type; complain.
die "Source path \"$srcpath\" is not a regular file or directory"; croak "Source path \"$srcpath\" is not a regular file or directory";
} }
1; 1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment