]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: use autodie::open where possible
authorEric Wong <e@80x24.org>
Tue, 29 Apr 2025 20:47:43 +0000 (20:47 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 May 2025 21:29:47 +0000 (21:29 +0000)
Outside of development scripts to run on cfarm machines, we can
rely on autodie being available to reduce noise in our code and
improve error message consistency.

lib/PublicInbox/GzipFilter.pm
lib/PublicInbox/HlMod.pm
lib/PublicInbox/LI2Wrap.pm
lib/PublicInbox/LeiInput.pm
lib/PublicInbox/LeiRediff.pm
t/lei-q-kw.t
t/mbox_reader.t

index a2e82a2d374257408f315addb11c6a203d5fa334..2d164a4bf5cbb440f646fc33317893ccb22eef18 100644 (file)
@@ -16,6 +16,7 @@
 package PublicInbox::GzipFilter;
 use strict;
 use parent qw(Exporter);
+use autodie qw(open);
 use Compress::Raw::Zlib qw(Z_OK);
 use PublicInbox::CompressNoop;
 use PublicInbox::Eml;
@@ -136,8 +137,7 @@ sub write {
 
 sub zfh {
        $_[0]->{zfh} // do {
-               open($_[0]->{zfh}, '>>', \($_[0]->{pbuf} //= '')) or
-                       die "open: $!";
+               open($_[0]->{zfh}, '>>', \($_[0]->{pbuf} //= ''));
                $_[0]->{zfh}
        };
 }
index f42ece80ededc4a04f06f453170c7320aaf94391..13ebe3f4755c133eb7aa02c0d4f870b7b1f6eb44 100644 (file)
@@ -15,6 +15,7 @@
 package PublicInbox::HlMod;
 use strict;
 use v5.10.1;
+use autodie qw(open);
 use highlight; # SWIG-generated stuff
 use PublicInbox::Hval qw(src_escape ascii_html);
 my $hl;
@@ -22,7 +23,7 @@ my $hl;
 sub _parse_filetypes ($) {
        my $ft_conf = $_[0]->getFiletypesConfPath('filetypes') or
                                die 'filetypes.conf not found by highlight';
-       open my $fh, '<', $ft_conf or die "failed to open($ft_conf): $!";
+       open my $fh, '<', $ft_conf;
        local $/;
        my $cfg = <$fh>;
        my %ext2lang;
index d4792b2518475e4ae21a868f773668fbdb61cd97..5b88a3cce00c6fedbf2fea7cf734a107c5f336c6 100644 (file)
@@ -7,11 +7,12 @@
 package PublicInbox::LI2Wrap;
 use v5.12;
 our @ISA = qw(Linux::Inotify2);
+use autodie qw(open);
 
 sub wrapclose {
        my ($inot) = @_;
        my $fd = $inot->fileno;
-       open my $fh, '<&=', $fd or die "open <&= $fd $!";
+       open my $fh, '<&=', $fd;
        bless $inot, __PACKAGE__;
 }
 
index a9443f3ae505bc42585aa6657771495c71fe2a10..f9d0d1e56f6fd3adb5c1d159c08efd69d10b696f 100644 (file)
@@ -4,6 +4,7 @@
 # parent class for LeiImport, LeiConvert, LeiIndex
 package PublicInbox::LeiInput;
 use v5.12;
+use autodie qw(open);
 use PublicInbox::DS;
 use PublicInbox::Git qw(git_exe);
 use PublicInbox::Spawn qw(which popen_rd);
@@ -215,8 +216,7 @@ sub input_path_url {
                my $mhr = PublicInbox::MHreader->new($dn, $lei->{3});
                $mhr->mh_read_one($n, $self->can('input_mh_cb'), $self);
        } elsif (-f $input && $ifmt eq 'eml') {
-               open my $fh, '<', $input or
-                                       return $lei->fail("open($input): $!");
+               open my $fh, '<', $input; # autodie::open hits caller eval
                $self->input_fh($ifmt, $fh, $input, @args);
        } elsif (-f _) {
                my $m = $lei->{opt}->{'lock'} //
index 6df2a96b0406f9829075a49e5c3f883cb47adcbc..876025b9d226c2a87465449bb17d492bb294eefc 100644 (file)
@@ -6,6 +6,7 @@ package PublicInbox::LeiRediff;
 use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
+use autodie qw(open);
 use File::Temp 0.19 (); # 0.19 for ->newdir
 use PublicInbox::Spawn qw(run_wait popen_wr which);
 use PublicInbox::MsgIter qw(msg_part_text);
@@ -49,7 +50,7 @@ sub solve_1 ($$$) {
                uarg => $self,
                inboxes => [ $self->{lxs}->locals, @{$self->{rmt}} ],
        }, 'PublicInbox::SolverGit';
-       open my $log, '+>', \(my $log_buf = '') or die "PerlIO::scalar: $!";
+       open my $log, '+>', \(my $log_buf = '');
        $self->{lei}->{log_buf} = \$log_buf;
        local $PublicInbox::DS::in_loop = 0; # waitpid synchronously
        $solver->solve($self->{lei}->{env}, $log, $oid_want, $hints);
index 63e4603786e16b5753de085ac9d042c74f7b3e31..1a6e4b6ec6af5befce2b53e210cc1d27a9ab37cf 100644 (file)
@@ -2,6 +2,7 @@
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
+use autodie qw(open);
 use POSIX qw(mkfifo);
 use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
 use IO::Uncompress::Gunzip qw(gunzip);
@@ -70,7 +71,7 @@ SKIP: {
        $cat = popen_rd(['cat', $o]);
        lei_ok(qw(q m:qp@example.com -o), "mboxrd:$o");
        my $buf = do { local $/; <$cat> };
-       open my $fh, '<', \$buf or BAIL_OUT $!;
+       open my $fh, '<', \$buf;
        PublicInbox::MboxReader->mboxrd($fh, sub {
                my ($eml) = @_;
                $eml->header_set('Status', 'RO');
@@ -86,7 +87,7 @@ my $read_file = sub {
                        BAIL_OUT 'gunzip';
                $buf;
        } else {
-               open my $fh, '+<', $_[0] or BAIL_OUT $!;
+               open my $fh, '+<', $_[0];
                do { local $/; <$fh> };
        }
 };
@@ -115,7 +116,7 @@ for my $sfx ('', '.gz') {
        $write_file->($o, $buf);
        lei_ok(qw(q -a -o), "mboxrd:$o", qw(m:testmessage@example.com));
        $buf = $read_file->($o);
-       open my $fh, '<', \$buf or BAIL_OUT "PerlIO::scalar $!";
+       open my $fh, '<', \$buf;
        my %res;
        PublicInbox::MboxReader->mboxrd($fh, sub {
                my ($eml) = @_;
@@ -166,18 +167,18 @@ $o = "$ENV{HOME}/kwmboxrd";
 lei_ok(qw(q -o), "mboxrd:$o", "m:$m", @inc);
 
 # emulate MUA marking mboxrd message as unread
-open my $fh, '<', $o or BAIL_OUT;
+open my $fh, '<', $o;
 my $s = do { local $/; <$fh> };
 $s =~ s/^Status: RO\n/Status: O\nX-Status: AF\n/sm or
        fail "failed to clear R flag in $s";
-open $fh, '>', $o or BAIL_OUT;
+open $fh, '>', $o;
 print $fh $s or BAIL_OUT;
 close $fh or BAIL_OUT;
 
 lei_ok(qw(q -o), "mboxrd:$o", 'm:bogus', @inc,
        \'clobber mbox to import keywords');
 lei_ok(qw(q -o), "mboxrd:$o", "m:$m", @inc);
-open $fh, '<', $o or BAIL_OUT;
+open $fh, '<', $o;
 $s = do { local $/; <$fh> };
 like($s, qr/^Status: O\nX-Status: AF\n/ms,
        'seen keyword gone in mbox, answered + flagged set');
@@ -212,7 +213,7 @@ my $in = $eml->as_string;
 lei_ok([qw(import -F eml --stdin)], undef, { 0 => \$in, %$lei_opt });
 is($lei_err, '', 'no errors from import');
 lei_ok(qw(q -f mboxrd), "m:$m");
-open $fh, '<', \$lei_out or BAIL_OUT $!;
+open $fh, '<', \$lei_out;
 my @res;
 PublicInbox::MboxReader->mboxrd($fh, sub { push @res, shift });
 is($res[0]->header('Status'), 'RO', 'seen kw set');
@@ -225,7 +226,7 @@ lei_ok([qw(import -F eml --stdin)], undef, { 0 => \$in, %$lei_opt });
 is($lei_err, '', 'no errors from 2nd import');
 lei_ok(qw(q -f mboxrd), "m:$m", 'l:another.example.com');
 my @another;
-open $fh, '<', \$lei_out or BAIL_OUT $!;
+open $fh, '<', \$lei_out;
 PublicInbox::MboxReader->mboxrd($fh, sub { push @another, shift });
 is($another[0]->header('Status'), 'RO', 'seen kw set');
 
@@ -246,7 +247,7 @@ is($another[0]->header('Status'), 'RO', 'seen kw set');
        scalar(@p) == 1 or xbail('multiple when 1 expected', \@p);
        like($p[0], qr/,PS/, 'passed (Forwarded) flag kept');
        lei_ok(qw(q -o), "mboxrd:$o.mboxrd", "m:$m");
-       open $fh, '<', "$o.mboxrd" or xbail $!;
+       open $fh, '<', "$o.mboxrd";
        my @res;
        PublicInbox::MboxReader->mboxrd($fh, sub { push @res, shift });
        scalar(@res) == 1 or xbail('multiple when 1 expected', \@res);
index 1fa9068e37175296fc1b974b8a7f98e2b3f732e6..3c072b5c2dfb005640e8a7fb9ae0d0b648fea478 100644 (file)
@@ -3,7 +3,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
-use autodie qw(seek);
+use autodie qw(open seek);
 use PublicInbox::TestCommon;
 use List::Util qw(shuffle);
 use PublicInbox::Eml;
@@ -46,7 +46,7 @@ my $check_fmt = sub {
        my $fmt = shift;
        my @order = shuffle(keys %raw);
        my $eml2mbox = PublicInbox::LeiToMail->can("eml2$fmt");
-       open my $fh, '+>', undef or BAIL_OUT "open: $!";
+       open my $fh, '+>', undef;
        for my $k (@order) {
                my $eml = PublicInbox::Eml->new($raw{$k});
                my $buf = $eml2mbox->($eml);
@@ -104,7 +104,7 @@ EOM
        # chop($no_blank_eom) eq "\n" or BAIL_OUT 'broken LF';
        for my $variant (qw(mboxrd mboxo)) {
                my @x;
-               open my $fh, '<', \$no_blank_eom or BAIL_OUT 'PerlIO::scalar';
+               open my $fh, '<', \$no_blank_eom;
                $reader->$variant($fh, sub { push @x, shift });
                is_deeply($x[0]->{bdy}, \"body1\n", 'LF preserved in 1st');
                is_deeply($x[1]->{bdy}, \"body2\n", 'no LF added in 2nd');
@@ -134,7 +134,7 @@ EOM
        for my $m (qw(mboxrd mboxcl mboxcl2 mboxo)) {
                my (@w, @x);
                local $SIG{__WARN__} = sub { push @w, @_ };
-               open my $fh, '<', \$html or xbail 'PerlIO::scalar';
+               open my $fh, '<', \$html;
                PublicInbox::MboxReader->$m($fh, sub {
                        push @x, $_[0]->as_string
                });