From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 6/6] emergency: make error messages more consistent
Date: Tue, 25 Apr 2023 11:02:58 +0000 [thread overview]
Message-ID: <20230425110258.2538658-7-e@80x24.org> (raw)
In-Reply-To: <20230425110258.2538658-1-e@80x24.org>
Showing "failed" is needless if we already know the program
is die-ing. We'll prefix "BUG:" to bug messages, "W:" to
non-fatal warnings to be consistent with our newer code such
as lei.
---
lib/PublicInbox/Emergency.pm | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm
index 56c58dd1..74a4069a 100644
--- a/lib/PublicInbox/Emergency.pm
+++ b/lib/PublicInbox/Emergency.pm
@@ -1,10 +1,9 @@
-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Emergency Maildir delivery for MDA
package PublicInbox::Emergency;
-use strict;
-use v5.10.1;
+use v5.12;
use Fcntl qw(:DEFAULT SEEK_SET);
use Sys::Hostname qw(hostname);
use IO::Handle; # ->flush
@@ -35,14 +34,14 @@ sub prepare {
my ($self, $strref) = @_;
my $pid = $$;
my $tmp_key = "tmp.$pid";
- die "already in transaction: $self->{$tmp_key}" if $self->{$tmp_key};
+ die "BUG: in transaction: $self->{$tmp_key}" if $self->{$tmp_key};
my ($tmp, $fh);
do {
$tmp = _fn_in($self, $pid, 'tmp');
$! = undef;
} while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_RDWR) and $! == EEXIST);
- print $fh $$strref or die "write failed: $!";
- $fh->flush or die "flush failed: $!";
+ print $fh $$strref or die "print: $!";
+ $fh->flush or die "flush: $!";
$self->{fh} = $fh;
$self->{$tmp_key} = $tmp;
}
@@ -51,15 +50,15 @@ sub abort {
my ($self) = @_;
delete $self->{fh};
my $tmp = delete $self->{"tmp.$$"} or return;
- unlink($tmp) or warn "Failed to unlink $tmp: $!";
+ unlink($tmp) or warn "W: unlink($tmp): $!";
undef;
}
sub fh {
my ($self) = @_;
- my $fh = $self->{fh} or die "{fh} not open!\n";
- seek($fh, 0, SEEK_SET) or die "seek(fh) failed: $!";
- sysseek($fh, 0, SEEK_SET) or die "sysseek(fh) failed: $!";
+ my $fh = $self->{fh} or die "BUG: {fh} not open";
+ seek($fh, 0, SEEK_SET) or die "seek: $!";
+ sysseek($fh, 0, SEEK_SET) or die "sysseek: $!";
$fh;
}
@@ -73,7 +72,7 @@ sub commit {
$new = _fn_in($self, $pid, 'new');
} while (!($ok = link($tmp, $new)) && $! == EEXIST);
die "link($tmp, $new): $!" unless $ok;
- unlink($tmp) or warn "Failed to unlink $tmp: $!";
+ unlink($tmp) or warn "W: unlink($tmp): $!";
}
sub DESTROY { commit($_[0]) }
prev parent reply other threads:[~2023-04-25 11:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 11:02 [PATCH 0/6] cleanups and error message consistency Eric Wong
2023-04-25 11:02 ` [PATCH 1/6] cindex: drop unneeded module use Eric Wong
2023-04-25 11:02 ` [PATCH 2/6] cindex: simplify tmpfile management for indexing Eric Wong
2023-04-25 11:02 ` [PATCH 3/6] cindex: simplify store_repo Eric Wong
2023-04-25 11:02 ` [PATCH 4/6] searchidxshard: use BUG error messages more consistently Eric Wong
2023-04-25 11:02 ` [PATCH 5/6] searchidx: reduce short-lived variables for TermGenerator Eric Wong
2023-04-25 11:02 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230425110258.2538658-7-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).