Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfde03e8

Browse files
committed
Use croak instead of die in Perl code when appropriate
1 parent32291ae commitfde03e8

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

‎src/backend/utils/mb/Unicode/convutils.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package convutils;
77

88
use strict;
99

10+
use Carp;
1011
use Exporter'import';
1112

1213
our@EXPORT =
@@ -698,7 +699,7 @@ sub make_charmap
698699
{
699700
my ($out,$charset,$direction,$verbose) =@_;
700701

701-
die"unacceptable direction :$direction"
702+
croak"unacceptable direction :$direction"
702703
if ($direction != TO_UNICODE &&$direction != FROM_UNICODE);
703704

704705
# In verbose mode, print a large comment with the source and comment of
@@ -759,7 +760,7 @@ sub make_charmap_combined
759760
{
760761
my ($charset,$direction) =@_;
761762

762-
die"unacceptable direction :$direction"
763+
croak"unacceptable direction :$direction"
763764
if ($direction != TO_UNICODE &&$direction != FROM_UNICODE);
764765

765766
my@combined;

‎src/bin/pg_rewind/RewindTest.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ package RewindTest;
3535
use strict;
3636
use warnings;
3737

38+
use Carp;
3839
use Config;
3940
use Exporter'import';
4041
use File::Copy;
@@ -228,7 +229,7 @@ sub run_pg_rewind
228229
{
229230

230231
# Cannot come here normally
231-
die("Incorrect test mode specified");
232+
croak("Incorrect test mode specified");
232233
}
233234

234235
# Now move back postgresql.conf with old settings

‎src/test/perl/PostgresNode.pm

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ package PostgresNode;
8282
use strict;
8383
use warnings;
8484

85+
use Carp;
8586
use Config;
8687
use Cwd;
8788
use Exporter'import';
@@ -359,7 +360,7 @@ sub set_replication_conf
359360
my$pgdata =$self->data_dir;
360361

361362
$self->hosteq$test_pghost
362-
ordie"set_replication_conf only works with the default host";
363+
orcroak"set_replication_conf only works with the default host";
363364

364365
openmy$hba,'>>',"$pgdata/pg_hba.conf";
365366
print$hba"\n# Allow replication (set up by PostgresNode.pm)\n";
@@ -624,7 +625,7 @@ sub init_from_backup
624625

625626
print
626627
"# Initializing node\"$node_name\" from backup\"$backup_name\" of node\"$root_name\"\n";
627-
die"Backup\"$backup_name\" does not exist at$backup_path"
628+
croak"Backup\"$backup_name\" does not exist at$backup_path"
628629
unless-d$backup_path;
629630

630631
mkdir$self->backup_dir;
@@ -1445,7 +1446,7 @@ sub lsn
14451446
'replay'=>'pg_last_wal_replay_lsn()');
14461447

14471448
$mode ='<undef>'if !defined($mode);
1448-
die"unknown mode for 'lsn': '$mode', valid modes are"
1449+
croak"unknown mode for 'lsn': '$mode', valid modes are"
14491450
.join(',',keys%modes)
14501451
if !defined($modes{$mode});
14511452

@@ -1490,7 +1491,7 @@ sub wait_for_catchup
14901491
$mode =defined($mode) ?$mode :'replay';
14911492
my%valid_modes =
14921493
('sent'=> 1,'write'=> 1,'flush'=> 1,'replay'=> 1);
1493-
die"unknown mode$mode for 'wait_for_catchup', valid modes are"
1494+
croak"unknown mode$mode for 'wait_for_catchup', valid modes are"
14941495
.join(',',keys(%valid_modes))
14951496
unlessexists($valid_modes{$mode});
14961497

@@ -1517,7 +1518,7 @@ sub wait_for_catchup
15171518
my$query =
15181519
qq[SELECT$lsn_expr <=${mode}_lsn FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name';];
15191520
$self->poll_query_until('postgres',$query)
1520-
ordie"timed out waiting for catchup";
1521+
orcroak"timed out waiting for catchup";
15211522
print"done\n";
15221523
}
15231524

@@ -1547,9 +1548,9 @@ sub wait_for_slot_catchup
15471548
$mode =defined($mode) ?$mode :'restart';
15481549
if (!($modeeq'restart' ||$modeeq'confirmed_flush'))
15491550
{
1550-
die"valid modes are restart, confirmed_flush";
1551+
croak"valid modes are restart, confirmed_flush";
15511552
}
1552-
die'target lsn must be specified'unlessdefined($target_lsn);
1553+
croak'target lsn must be specified'unlessdefined($target_lsn);
15531554
print"Waiting for replication slot"
15541555
.$slot_name ."'s"
15551556
.$mode
@@ -1559,7 +1560,7 @@ sub wait_for_slot_catchup
15591560
my$query =
15601561
qq[SELECT '$target_lsn' <=${mode}_lsn FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name';];
15611562
$self->poll_query_until('postgres',$query)
1562-
ordie"timed out waiting for catchup";
1563+
orcroak"timed out waiting for catchup";
15631564
print"done\n";
15641565
}
15651566

@@ -1588,7 +1589,7 @@ null columns.
15881589
subquery_hash
15891590
{
15901591
my ($self,$dbname,$query,@columns) =@_;
1591-
die'calls in array context for multi-row results not supported yet'
1592+
croak'calls in array context for multi-row results not supported yet'
15921593
if (wantarray);
15931594

15941595
# Replace __COLUMNS__ if found
@@ -1663,8 +1664,8 @@ sub pg_recvlogical_upto
16631664

16641665
my$timeout_exception ='pg_recvlogical timed out';
16651666

1666-
die'slot name must be specified'unlessdefined($slot_name);
1667-
die'endpos must be specified'unlessdefined($endpos);
1667+
croak'slot name must be specified'unlessdefined($slot_name);
1668+
croak'endpos must be specified'unlessdefined($endpos);
16681669

16691670
my@cmd = (
16701671
'pg_recvlogical','-S',$slot_name,'--dbname',
@@ -1674,7 +1675,7 @@ sub pg_recvlogical_upto
16741675

16751676
while (my ($k,$v) =each%plugin_options)
16761677
{
1677-
die"= is not permitted to appear in replication option name"
1678+
croak"= is not permitted to appear in replication option name"
16781679
if ($k =~qr/=/);
16791680
push@cmd,"-o","$k=$v";
16801681
}

‎src/test/perl/RecursiveCopy.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package RecursiveCopy;
1919
use strict;
2020
use warnings;
2121

22+
use Carp;
2223
use File::Basename;
2324
use File::Copy;
2425

@@ -68,7 +69,7 @@ sub copypath
6869

6970
if (defined$params{filterfn})
7071
{
71-
die"if specified, filterfn must be a subroutine reference"
72+
croak"if specified, filterfn must be a subroutine reference"
7273
unlessdefined(ref$params{filterfn})
7374
and (ref$params{filterfn}eq'CODE');
7475

@@ -80,7 +81,7 @@ sub copypath
8081
}
8182

8283
# Complain if original path is bogus, because _copypath_recurse won't.
83-
die"\"$base_src_dir\" does not exist"if !-e$base_src_dir;
84+
croak"\"$base_src_dir\" does not exist"if !-e$base_src_dir;
8485

8586
# Start recursive copy from current directory
8687
return _copypath_recurse($base_src_dir,$base_dest_dir,"",$filterfn);
@@ -98,11 +99,11 @@ sub _copypath_recurse
9899

99100
# Check for symlink -- needed only on source dir
100101
# (note: this will fall through quietly if file is already gone)
101-
die"Cannot operate on symlink\"$srcpath\""if-l$srcpath;
102+
croak"Cannot operate on symlink\"$srcpath\""if-l$srcpath;
102103

103104
# Abort if destination path already exists. Should we allow directories
104105
# to exist already?
105-
die"Destination path\"$destpath\" already exists"if-e$destpath;
106+
croak"Destination path\"$destpath\" already exists"if-e$destpath;
106107

107108
# If this source path is a file, simply copy it to destination with the
108109
# same name and we're done.
@@ -148,7 +149,7 @@ sub _copypath_recurse
148149
return 1if !-e$srcpath;
149150

150151
# Else it's some weird file type; complain.
151-
die"Source path\"$srcpath\" is not a regular file or directory";
152+
croak"Source path\"$srcpath\" is not a regular file or directory";
152153
}
153154

154155
1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp