Use croak instead of die in Perl code when appropriate
authorPeter Eisentraut <[email protected]>
Sat, 24 Feb 2018 19:35:54 +0000 (14:35 -0500)
committerPeter Eisentraut <[email protected]>
Sat, 24 Feb 2018 19:54:16 +0000 (14:54 -0500)
src/backend/utils/mb/Unicode/convutils.pm
src/bin/pg_rewind/RewindTest.pm
src/test/perl/PostgresNode.pm
src/test/perl/RecursiveCopy.pm

index 854df8cf2a88b64f6a19fd56e2652959dd41e5af..69494d0df32a131a05ab6885e4644b03606e8aec 100644 (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;
index 42fd577f219e0fd27001c2839289e8782eb1cfed..00b5b42dd796499667fe2942f9616cf62ce9c37c 100644 (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
index 1d5ac4ee3543f1d9e0286a6976e49986cef29fb2..80188315f15d265c872dd7a2dfb7c2c35ad0dabe 100644 (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";
        }
index 19f7dd2fffe511cd303afec0dabb6c6a22fe1885..5bce720b3567bc1af5ea36bb3f9ea20d6c27de6f 100644 (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;