]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: consistent IO::Handle->flush error handling
authorEric Wong <e@80x24.org>
Sat, 7 Jun 2025 19:48:37 +0000 (19:48 +0000)
committerEric Wong <e@80x24.org>
Mon, 9 Jun 2025 23:55:31 +0000 (23:55 +0000)
We'll attempt to stringify the failing IO handle in case
Perl can output more info about the object.  Furthermore,
we can disable checks for `print' failures preceding ->flush
since they're redundant and a waste of code.

lib/PublicInbox/Emergency.pm
lib/PublicInbox/GitHTTPBackend.pm
lib/PublicInbox/IdxStack.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/SolverGit.pm
lib/PublicInbox/Spawn.pm

index 7e9faad02bd7b2e1af5068ebee052536620cfa0a..6452e4059f5d2830da39e0025096a236bf99e5f3 100644 (file)
@@ -40,8 +40,8 @@ sub prepare {
        do {
                $tmp = _fn_in($self, $pid, 'tmp');
        } while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_RDWR) and $! == EEXIST);
-       print $fh $$strref or die "print: $!";
-       $fh->flush or die "flush: $!";
+       print $fh $$strref;
+       $fh->flush or die "$fh->flush: $!";
        $self->{fh} = $fh;
        $self->{$tmp_key} = $tmp;
 }
index 3dce4dbb4bb87eea8466a494022c30513aa01fe3..de50caff6a94c25b523d3da01ac4129779bda652 100644 (file)
@@ -124,7 +124,7 @@ sub input_prepare {
                print $in $buf;
        }
        # ensure it's visible to git-http-backend(1):
-       $in->flush // die "flush: $!";
+       $in->flush or die "$in->flush: $!";
        sysseek $in, 0, SEEK_SET;
        $in;
 }
index 8816d96b0ec4e5ee80b66c54be4b269d3a306ee5..257c82bbc0cc9fb7e0c7d8be1faffc4ef5864bd3 100644 (file)
@@ -42,7 +42,7 @@ sub num_records {
 sub read_prepare {
        my ($self) = @_;
        my $io = $self->{rd} = delete($self->{wr});
-       $io->flush or die "flush: $!";
+       $io->flush or die "$io->flush: $!";
        $self;
 }
 
index 4ed3881fb0c60cf36a65104ca085e9e787a55847..ca9953ce0cd0a0ec46bea94207eeee616b216d79 100644 (file)
@@ -372,7 +372,7 @@ sub index_body_text {
        if ($$sref =~ /^(?:diff|---|\+\+\+) /ms && !$PATCHID_BROKEN) {
                my $git = ($self->{ibx} // $self->{eidx} // $self)->git;
                my $fh = PublicInbox::IO::write_file '+>:utf8', undef, $$sref;
-               $fh->flush or die "flush: $!";
+               $fh->flush or die "$fh->flush: $!";
                sysseek($fh, 0, SEEK_SET);
                $rd = popen_rd($git->cmd(qw(patch-id --stable)), undef,
                                { 0 => $fh });
index cca1a5169c1d6e5cfca5612f79bb44002bc29e67..b12ae4e4f0d3671e39450b48a7e468a232513853 100644 (file)
@@ -341,8 +341,8 @@ sub prepare_index ($) {
        my $mode_a = $di->{mode_a} // '100644';
 
        my $in = tmpfile("update-index.$oid_full") or die "tmpfile: $!";
-       print $in "$mode_a $oid_full\t$path_a\0" or die "print: $!";
-       $in->flush or die "flush: $!";
+       print $in "$mode_a $oid_full\t$path_a\0";
+       $in->flush or die "$in->flush: $!";
        sysseek $in, 0, SEEK_SET;
 
        dbg($self, 'preparing index');
index 7d4671c36c60e70c1fbc93d44f4ada7b14bcb3ae..9f4752f9cb6219141ef22f579afb6ff8315a8ecb 100644 (file)
@@ -370,7 +370,7 @@ sub spawn ($;$$) {
                        $opt->{"fh.$child_fd"} = $fh; # for read_out_err
                        if ($child_fd == 0) {
                                print $fh $$pfd;
-                               $fh->flush or die "flush: $!";
+                               $fh->flush or die "$fh->flush: $!";
                                sysseek($fh, 0, SEEK_SET);
                        }
                        $pfd = fileno($fh);