From: Eric Wong Date: Sat, 7 Jun 2025 19:48:37 +0000 (+0000) Subject: treewide: consistent IO::Handle->flush error handling X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02c51cf4eec2383ef4d329d3025e09060d28ee1c;p=thirdparty%2Fpublic-inbox.git treewide: consistent IO::Handle->flush error handling 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. --- diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm index 7e9faad02..6452e4059 100644 --- a/lib/PublicInbox/Emergency.pm +++ b/lib/PublicInbox/Emergency.pm @@ -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; } diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 3dce4dbb4..de50caff6 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -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; } diff --git a/lib/PublicInbox/IdxStack.pm b/lib/PublicInbox/IdxStack.pm index 8816d96b0..257c82bbc 100644 --- a/lib/PublicInbox/IdxStack.pm +++ b/lib/PublicInbox/IdxStack.pm @@ -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; } diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 4ed3881fb..ca9953ce0 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -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 }); diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm index cca1a5169..b12ae4e4f 100644 --- a/lib/PublicInbox/SolverGit.pm +++ b/lib/PublicInbox/SolverGit.pm @@ -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'); diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 7d4671c36..9f4752f9c 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -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);