Use croak instead of die in Perl code when appropriate

This commit is contained in:
Peter Eisentraut 2018-02-24 14:35:54 -05:00
parent 32291aed49
commit fde03e8b55
4 changed files with 24 additions and 20 deletions

View File

@ -7,6 +7,7 @@ package convutils;
use strict;
use Carp;
use Exporter 'import';
our @EXPORT =
@ -698,7 +699,7 @@ sub make_charmap
{
my ($out, $charset, $direction, $verbose) = @_;
die "unacceptable direction : $direction"
croak "unacceptable direction : $direction"
if ($direction != TO_UNICODE && $direction != FROM_UNICODE);
# In verbose mode, print a large comment with the source and comment of
@ -759,7 +760,7 @@ sub make_charmap_combined
{
my ($charset, $direction) = @_;
die "unacceptable direction : $direction"
croak "unacceptable direction : $direction"
if ($direction != TO_UNICODE && $direction != FROM_UNICODE);
my @combined;

View File

@ -35,6 +35,7 @@ package RewindTest;
use strict;
use warnings;
use Carp;
use Config;
use Exporter 'import';
use File::Copy;
@ -228,7 +229,7 @@ sub run_pg_rewind
{
# Cannot come here normally
die("Incorrect test mode specified");
croak("Incorrect test mode specified");
}
# Now move back postgresql.conf with old settings

View File

@ -82,6 +82,7 @@ package PostgresNode;
use strict;
use warnings;
use Carp;
use Config;
use Cwd;
use Exporter 'import';
@ -359,7 +360,7 @@ sub set_replication_conf
my $pgdata = $self->data_dir;
$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";
print $hba "\n# Allow replication (set up by PostgresNode.pm)\n";
@ -624,7 +625,7 @@ sub init_from_backup
print
"# 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;
mkdir $self->backup_dir;
@ -1445,7 +1446,7 @@ sub lsn
'replay' => 'pg_last_wal_replay_lsn()');
$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)
if !defined($modes{$mode});
@ -1490,7 +1491,7 @@ sub wait_for_catchup
$mode = defined($mode) ? $mode : 'replay';
my %valid_modes =
('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))
unless exists($valid_modes{$mode});
@ -1517,7 +1518,7 @@ sub wait_for_catchup
my $query =
qq[SELECT $lsn_expr <= ${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';];
$self->poll_query_until('postgres', $query)
or die "timed out waiting for catchup";
or croak "timed out waiting for catchup";
print "done\n";
}
@ -1547,9 +1548,9 @@ sub wait_for_slot_catchup
$mode = defined($mode) ? $mode : 'restart';
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 "
. $slot_name . "'s "
. $mode
@ -1559,7 +1560,7 @@ sub wait_for_slot_catchup
my $query =
qq[SELECT '$target_lsn' <= ${mode}_lsn FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name';];
$self->poll_query_until('postgres', $query)
or die "timed out waiting for catchup";
or croak "timed out waiting for catchup";
print "done\n";
}
@ -1588,7 +1589,7 @@ null columns.
sub query_hash
{
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);
# Replace __COLUMNS__ if found
@ -1663,8 +1664,8 @@ sub pg_recvlogical_upto
my $timeout_exception = 'pg_recvlogical timed out';
die 'slot name must be specified' unless defined($slot_name);
die 'endpos must be specified' unless defined($endpos);
croak 'slot name must be specified' unless defined($slot_name);
croak 'endpos must be specified' unless defined($endpos);
my @cmd = (
'pg_recvlogical', '-S', $slot_name, '--dbname',
@ -1674,7 +1675,7 @@ sub pg_recvlogical_upto
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/=/);
push @cmd, "-o", "$k=$v";
}

View File

@ -19,6 +19,7 @@ package RecursiveCopy;
use strict;
use warnings;
use Carp;
use File::Basename;
use File::Copy;
@ -68,7 +69,7 @@ sub copypath
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})
and (ref $params{filterfn} eq 'CODE');
@ -80,7 +81,7 @@ sub copypath
}
# 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
return _copypath_recurse($base_src_dir, $base_dest_dir, "", $filterfn);
@ -98,11 +99,11 @@ sub _copypath_recurse
# Check for symlink -- needed only on source dir
# (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
# 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
# same name and we're done.
@ -148,7 +149,7 @@ sub _copypath_recurse
return 1 if !-e $srcpath;
# 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;