Skip to content

Commit f8721bd

Browse files
committed
Use croak instead of die in Perl code when appropriate
1 parent e7c2b95 commit f8721bd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/test/perl/TestLib.pm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ package TestLib;
4343
use strict;
4444
use warnings;
4545

46+
use Carp;
4647
use Config;
4748
use Cwd;
4849
use Exporter 'import';
@@ -421,7 +422,7 @@ sub slurp_dir
421422
{
422423
my ($dir) = @_;
423424
opendir(my $dh, $dir)
424-
or die "could not opendir \"$dir\": $!";
425+
or croak "could not opendir \"$dir\": $!";
425426
my @direntries = readdir $dh;
426427
closedir $dh;
427428
return @direntries;
@@ -443,19 +444,19 @@ sub slurp_file
443444
if ($Config{osname} ne 'MSWin32')
444445
{
445446
open(my $in, '<', $filename)
446-
or die "could not read \"$filename\": $!";
447+
or croak "could not read \"$filename\": $!";
447448
$contents = <$in>;
448449
close $in;
449450
}
450451
else
451452
{
452453
my $fHandle = createFile($filename, "r", "rwd")
453-
or die "could not open \"$filename\": $^E";
454+
or croak "could not open \"$filename\": $^E";
454455
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
455-
or die "could not read \"$filename\": $^E\n";
456+
or croak "could not read \"$filename\": $^E\n";
456457
$contents = <$fh>;
457458
CloseHandle($fHandle)
458-
or die "could not close \"$filename\": $^E\n";
459+
or croak "could not close \"$filename\": $^E\n";
459460
}
460461
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
461462
return $contents;
@@ -474,7 +475,7 @@ sub append_to_file
474475
{
475476
my ($filename, $str) = @_;
476477
open my $fh, ">>", $filename
477-
or die "could not write \"$filename\": $!";
478+
or croak "could not write \"$filename\": $!";
478479
print $fh $str;
479480
close $fh;
480481
return;

0 commit comments

Comments
 (0)