unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/4] lei: improve ->fail internal API
Date: Fri, 22 Sep 2023 21:13:14 +0000	[thread overview]
Message-ID: <20230922211316.3060039-3-e@80x24.org> (raw)
In-Reply-To: <20230922211316.3060039-1-e@80x24.org>

Allow the exit code to be the first argument intead of the last
to match our ->child_error, as well as the BSD err(3) API.
We'll also avoid shifting user-passed exit codes so $? can be
passed as-is without losing signal information.
---
 lib/PublicInbox/LEI.pm       | 19 ++++++++++++-------
 lib/PublicInbox/LeiToMail.pm |  2 +-
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index c61ce76d..368f9357 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -29,6 +29,7 @@ use File::Path ();
 use File::Spec;
 use Carp ();
 use Sys::Syslog qw(openlog syslog closelog);
+use Scalar::Util qw(looks_like_number);
 our $quit = \&CORE::exit;
 our ($current_lei, $errors_log, $listener, $oldset, $dir_idle);
 my $GLP = Getopt::Long::Parser->new;
@@ -518,13 +519,17 @@ sub sigpipe_handler { # handles SIGPIPE from @WQ_KEYS workers
 	fail_handler($_[0], 13, delete $_[0]->{1});
 }
 
-sub fail ($$;$) {
-	my ($self, $msg, $exit_code) = @_;
-	local $current_lei = $self;
-	$self->{failed}++;
-	warn(substr($msg, -1, 1) eq "\n" ? $msg : "$msg\n") if defined $msg;
-	$self->{pkt_op_p}->pkt_do('fail_handler') if $self->{pkt_op_p};
-	x_it($self, ($exit_code // 1) << 8);
+sub fail ($;@) {
+	my ($lei, @msg) = @_;
+	my $exit_code = looks_like_number($msg[0]) ? shift(@msg) : undef;
+	local $current_lei = $lei;
+	$lei->{failed}++;
+	if (@msg) {
+		push @msg, "\n" if substr($msg[-1], -1, 1);
+		warn @msg;
+	}
+	$lei->{pkt_op_p}->pkt_do('fail_handler') if $lei->{pkt_op_p};
+	x_it($lei, $exit_code // (1 << 8));
 	undef;
 }
 
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index e357ee00..7c7967c8 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -154,7 +154,7 @@ sub reap_compress { # awaitpid callback
 	my ($pid, $lei) = @_;
 	my $cmd = delete $lei->{"pid.$pid"};
 	return if $? == 0;
-	$lei->fail("@$cmd failed", $? >> 8);
+	$lei->fail($?, "@$cmd failed");
 }
 
 sub _post_augment_mbox { # open a compressor process from top-level process

  parent reply	other threads:[~2023-09-22 21:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22 21:13 [PATCH 0/4] small lei fixes Eric Wong
2023-09-22 21:13 ` [PATCH 1/4] lei blob|rediff: fix usage of lei->fail Eric Wong
2023-09-22 21:13 ` Eric Wong [this message]
2023-09-22 21:13 ` [PATCH 3/4] lei_to_mail: drop awkward duplication of $lei object Eric Wong
2023-09-22 21:13 ` [PATCH 4/4] lei: use File::Temp for listing saved searches Eric Wong

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=20230922211316.3060039-3-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).