Commit f8721bd7 authored by Peter Eisentraut's avatar Peter Eisentraut

Use croak instead of die in Perl code when appropriate

parent e7c2b95d
...@@ -43,6 +43,7 @@ package TestLib; ...@@ -43,6 +43,7 @@ package TestLib;
use strict; use strict;
use warnings; use warnings;
use Carp;
use Config; use Config;
use Cwd; use Cwd;
use Exporter 'import'; use Exporter 'import';
...@@ -421,7 +422,7 @@ sub slurp_dir ...@@ -421,7 +422,7 @@ sub slurp_dir
{ {
my ($dir) = @_; my ($dir) = @_;
opendir(my $dh, $dir) opendir(my $dh, $dir)
or die "could not opendir \"$dir\": $!"; or croak "could not opendir \"$dir\": $!";
my @direntries = readdir $dh; my @direntries = readdir $dh;
closedir $dh; closedir $dh;
return @direntries; return @direntries;
...@@ -443,19 +444,19 @@ sub slurp_file ...@@ -443,19 +444,19 @@ sub slurp_file
if ($Config{osname} ne 'MSWin32') if ($Config{osname} ne 'MSWin32')
{ {
open(my $in, '<', $filename) open(my $in, '<', $filename)
or die "could not read \"$filename\": $!"; or croak "could not read \"$filename\": $!";
$contents = <$in>; $contents = <$in>;
close $in; close $in;
} }
else else
{ {
my $fHandle = createFile($filename, "r", "rwd") my $fHandle = createFile($filename, "r", "rwd")
or die "could not open \"$filename\": $^E"; or croak "could not open \"$filename\": $^E";
OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r') OsFHandleOpen(my $fh = IO::Handle->new(), $fHandle, 'r')
or die "could not read \"$filename\": $^E\n"; or croak "could not read \"$filename\": $^E\n";
$contents = <$fh>; $contents = <$fh>;
CloseHandle($fHandle) CloseHandle($fHandle)
or die "could not close \"$filename\": $^E\n"; or croak "could not close \"$filename\": $^E\n";
} }
$contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys'; $contents =~ s/\r\n/\n/g if $Config{osname} eq 'msys';
return $contents; return $contents;
...@@ -474,7 +475,7 @@ sub append_to_file ...@@ -474,7 +475,7 @@ sub append_to_file
{ {
my ($filename, $str) = @_; my ($filename, $str) = @_;
open my $fh, ">>", $filename open my $fh, ">>", $filename
or die "could not write \"$filename\": $!"; or croak "could not write \"$filename\": $!";
print $fh $str; print $fh $str;
close $fh; close $fh;
return; return;
......
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