Use croak/carp instead of die/warn (PBP)

This commit is contained in:
Dan Church 2023-07-20 14:30:05 -05:00
parent 4e2e94881b
commit 3e96b9bc19
Signed by: h3xx
GPG Key ID: EA2BF379CD2CDBD0
3 changed files with 8 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package Directory::Simplify::Instruction::Generator;
use strict;
use warnings;
use overload '""' => 'as_string';
use Carp qw/ carp /;
require File::Compare;
# :squash-remove-start:
@ -126,7 +127,7 @@ sub _entries_contents_match {
# warn about hash collision
unless ($contents_same) {
warn "Hash collision between files:\n* $entry_a->{name}\n* $entry_b->{name}\n (don't panic)\n";
carp "Hash collision between files:\n* $entry_a->{name}\n* $entry_b->{name}\n (don't panic)\n";
}
return $contents_same;
}
@ -147,7 +148,7 @@ sub instructions {
my @non_readonly;
foreach my $entry (@{$bucket}) {
unless (-w $entry->{dirname}) {
warn "Warning: $entry->{name} not able to be unlinked!";
carp "Warning: $entry->{name} not able to be unlinked!";
}
push @non_readonly, $entry;
}

View File

@ -2,6 +2,7 @@ package Directory::Simplify::Instruction::Hardlink;
use strict;
use warnings;
use overload '""' => 'as_string';
use Carp qw/ croak /;
# :squash-remove-start:
require Directory::Simplify::Utils;
@ -20,10 +21,10 @@ sub run {
# hard link the files
unless (unlink $self->{target}->{name}) {
die "Failed to remove file `$self->{target}->{name}': $!\n";
croak "Failed to remove file `$self->{target}->{name}': $!\n";
}
unless (link $self->{source}->{name}, $self->{target}->{name}) {
die "Failed to hard link `$self->{source}->{name}' => `$self->{target}->{name}': $!";
croak "Failed to hard link `$self->{source}->{name}' => `$self->{target}->{name}': $!";
}
# bookkeeping
++$self->{source}->{nlink};

View File

@ -3,6 +3,7 @@ use strict;
use warnings;
use Test::More 'no_plan';
use Carp qw/ croak /;
use TestFunctions;
@ -20,7 +21,7 @@ sub put_file {
my $bytes = 1048576; # 1 MB
foreach my $file (@files) {
open my $fh, '>', $file
or die "Failed to open file $file for writing: $!";
or croak("Failed to open file $file for writing: $!");
for (my $bytes_written = 0; $bytes_written < $bytes; ++$bytes_written) {
print $fh 'A';
}