From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BA49F1FA01 for ; Tue, 19 Oct 2021 09:33:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/11] lei: use die for external and query handling Date: Tue, 19 Oct 2021 09:33:38 +0000 Message-Id: <20211019093346.30885-4-e@80x24.org> In-Reply-To: <20211019093346.30885-1-e@80x24.org> References: <20211019093346.30885-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This allows "lei up" to continue processing unrelated externals if on output fails. --- lib/PublicInbox/LeiExternal.pm | 4 ++-- lib/PublicInbox/LeiQuery.pm | 12 +++++------- lib/PublicInbox/LeiSavedSearch.pm | 8 ++++---- lib/PublicInbox/LeiUp.pm | 4 ++-- lib/PublicInbox/LeiXSearch.pm | 7 ++++--- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index 701d1ad53adf..851715d7099c 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -101,9 +101,9 @@ sub get_externals { return (ext_canonicalize($loc)); } if (scalar(@m) == 0) { - $self->fail("`$loc' is unknown"); + die "`$loc' is unknown\n"; } else { - $self->fail("`$loc' is ambiguous:\n", map { "\t$_\n" } @m); + die("`$loc' is ambiguous:\n", map { "\t$_\n" } @m, "\n"); } (); } diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm index ec2ece051492..56b82acc8b5b 100644 --- a/lib/PublicInbox/LeiQuery.pm +++ b/lib/PublicInbox/LeiQuery.pm @@ -18,17 +18,15 @@ sub _start_query { # used by "lei q" and "lei up" PublicInbox::LeiOverview->new($self) or return; my $opt = $self->{opt}; my ($xj, $mj) = split(/,/, $opt->{jobs} // ''); - if (defined($xj) && $xj ne '' && $xj !~ /\A[1-9][0-9]*\z/) { - return $self->fail("`$xj' search jobs must be >= 1"); - } + (defined($xj) && $xj ne '' && $xj !~ /\A[1-9][0-9]*\z/) and + die "`$xj' search jobs must be >= 1\n"; my $lxs = $self->{lxs}; $xj ||= $lxs->concurrency($opt); # allow: "--jobs ,$WRITER_ONLY" my $nproc = $lxs->detect_nproc || 1; # don't memoize, schedtool(1) exists $xj = $nproc if $xj > $nproc; $lxs->{-wq_nr_workers} = $xj; - if (defined($mj) && $mj !~ /\A[1-9][0-9]*\z/) { - return $self->fail("`$mj' writer jobs must be >= 1"); - } + (defined($mj) && $mj !~ /\A[1-9][0-9]*\z/) and + die "`$mj' writer jobs must be >= 1\n"; my $l2m = $self->{l2m}; # we use \1 (a ref) to distinguish between default vs. user-supplied if ($l2m && grep { $opt->{$_} //= \1 } (qw(mail-sync import-remote @@ -112,7 +110,7 @@ sub lxs_prepare { } } ($lxs->locals || $lxs->remotes) ? ($self->{lxs} = $lxs) : - $self->fail('no local or remote inboxes to search'); + die("no local or remote inboxes to search\n"); } # the main "lei q SEARCH_TERMS" method diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index 3e10f780ad02..b2f1ad1027d3 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -96,7 +96,7 @@ sub translate_dedupe ($$) { my $dd = $lei->{opt}->{dedupe} // 'content'; return 1 if $dd eq 'content'; # the default return $self->{"-dedupe_$dd"} = 1 if ($dd eq 'oid' || $dd eq 'mid'); - $lei->fail("--dedupe=$dd requires --no-save"); + die("--dedupe=$dd requires --no-save\n"); } sub up { # updating existing saved search via "lei up" @@ -105,9 +105,9 @@ sub up { # updating existing saved search via "lei up" my $self = bless { ale => $lei->ale }, $cls; my $dir = $dst; output2lssdir($self, $lei, \$dir, \$f) or - return $lei->fail("--no-save was used with $dst cwd=". - $lei->rel2abs('.')); - $self->{-cfg} = $lei->cfg_dump($f) // return $lei->fail; + return die("--no-save was used with $dst cwd=". + $lei->rel2abs('.')."\n"); + $self->{-cfg} = $lei->cfg_dump($f) // return $lei->child_error; $self->{-ovf} = "$dir/over.sqlite3"; $self->{'-f'} = $f; $self->{lock_path} = "$self->{-f}.flock"; diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm index c35b2e42d49f..4fd0290c7612 100644 --- a/lib/PublicInbox/LeiUp.pm +++ b/lib/PublicInbox/LeiUp.pm @@ -19,7 +19,7 @@ sub up1 ($$) { my $f = $lss->{'-f'}; my $mset_opt = $lei->{mset_opt} = { relevance => -2 }; my $q = $mset_opt->{q_raw} = $lss->{-cfg}->{'lei.q'} // - return $lei->fail("lei.q unset in $f"); + die("lei.q unset in $f (out=$out)\n"); my $lse = $lei->{lse} // die 'BUG: {lse} missing'; if (ref($q)) { $mset_opt->{qstr} = $lse->query_argv_to_string($lse->git, $q); @@ -36,7 +36,7 @@ sub up1 ($$) { $lei->{opt}->{$k} //= $v; } my $o = $lei->{opt}->{output} // ''; - return $lei->fail("lei.q.output unset in $f (out=$out)") if $o eq ''; + return die("lei.q.output unset in $f (out=$out)\n") if $o eq ''; $lss->translate_dedupe($lei) or return; $lei->{lss} = $lss; # for LeiOverview->new and query_remote_mboxrd my $lxs = $lei->lxs_prepare or return; diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index 8ab84b15c00b..119070a289de 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -142,11 +142,11 @@ sub wait_startq ($) { delete $lei->{opt}->{verbose}; delete $lei->{-progress}; } else { - $lei->fail("$$ WTF `$do_augment_done'"); + die "BUG: do_augment_done=`$do_augment_done'"; } return; } - return $lei->fail("$$ wait_startq: $!") unless $!{EINTR}; + die "wait_startq: $!" unless $!{EINTR}; } } @@ -473,7 +473,8 @@ sub do_post_augment { $lei->fail("$err"); } if (!$err && delete $lei->{early_mua}) { # non-augment case - $lei->start_mua; + eval { $lei->start_mua }; + $lei->fail($@) if $@; } close(delete $lei->{au_done}); # triggers wait_startq in lei_xsearch }