From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 04/12] lei: simplify internal arg2folder usage
Date: Tue, 21 Sep 2021 07:41:51 +0000 [thread overview]
Message-ID: <20210921074159.20052-5-e@80x24.org> (raw)
In-Reply-To: <20210921074159.20052-1-e@80x24.org>
We can set opt->{quiet} for (internal) 'note-event' command
to quiet ->qerr, since we use ->qerr everywhere else. And
we'll just die() instead of setting a ->{fail} message, since
eval + die are more inline with the rest of our Perl code.
---
lib/PublicInbox/LEI.pm | 2 +-
lib/PublicInbox/LeiExportKw.pm | 4 +---
lib/PublicInbox/LeiForgetMailSync.pm | 4 +---
lib/PublicInbox/LeiInspect.pm | 17 +++++------------
lib/PublicInbox/LeiLcat.pm | 5 ++---
lib/PublicInbox/LeiMailSync.pm | 17 ++++++-----------
lib/PublicInbox/LeiNoteEvent.pm | 5 +++--
lib/PublicInbox/LeiRefreshMailSync.pm | 4 +---
8 files changed, 20 insertions(+), 38 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 148a5b1e..f94bfa45 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1194,7 +1194,7 @@ sub dir_idle_handler ($) { # PublicInbox::DirIdle callback
$lei->dispatch('note-event',
"maildir:$mdir", $nc, $bn, $fn);
};
- warn "E note-event $f: $@\n" if $@;
+ warn "E: note-event $f: $@\n" if $@;
}
}
if ($ev->can('cancel') && ($ev->IN_IGNORE || $ev->IN_UNMOUNT)) {
diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm
index 8c5fbc13..d5533a2a 100644
--- a/lib/PublicInbox/LeiExportKw.pm
+++ b/lib/PublicInbox/LeiExportKw.pm
@@ -92,9 +92,7 @@ EOM
$lms->group2folders($lei, $all, \@folders) or return;
@folders = grep(/\A(?:maildir|imaps?):/i, @folders);
} else {
- my $err = $lms->arg2folder($lei, \@folders);
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- return $lei->fail($err->{fail}) if $err->{fail};
+ $lms->arg2folder($lei, \@folders); # may die
}
$lms->lms_pause;
my $self = bless { lse => $sto->search, lms => $lms }, __PACKAGE__;
diff --git a/lib/PublicInbox/LeiForgetMailSync.pm b/lib/PublicInbox/LeiForgetMailSync.pm
index 701f48d2..d85616cc 100644
--- a/lib/PublicInbox/LeiForgetMailSync.pm
+++ b/lib/PublicInbox/LeiForgetMailSync.pm
@@ -16,9 +16,7 @@ sub lei_forget_mail_sync {
my ($lei, @folders) = @_;
my $lms = $lei->lms or return;
$lms->lms_write_prepare;
- my $err = $lms->arg2folder($lei, \@folders);
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- return $lei->fail($err->{fail}) if $err->{fail};
+ $lms->arg2folder($lei, \@folders); # may die
$lms->forget_folders(@folders);
}
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index 722ba5b2..8e128580 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -46,10 +46,9 @@ sub inspect_nntp_range {
my $ent = {};
my $ret = { "$uri" => $ent };
my $lms = $lei->lms or return $ret;
- my $err = $lms->arg2folder($lei, my $folders = [ $$uri ]);
- if ($err) {
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- }
+ my $folders = [ $$uri ];
+ eval { $lms->arg2folder($lei, $folders) };
+ $lei->qerr("# no folders match $$uri (non-fatal)") if $@;
$end //= $beg;
for my $art ($beg..$end) {
my @oidhex = map { unpack('H*', $_) }
@@ -65,14 +64,8 @@ sub inspect_sync_folder ($$) {
my $ent = {};
my $lms = $lei->lms or return $ent;
my $folders = [ $folder ];
- my $err = $lms->arg2folder($lei, $folders);
- if ($err) {
- if ($err->{fail}) {
- $lei->qerr("# no folders match $folder (non-fatal)");
- @$folders = ();
- }
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- }
+ eval { $lms->arg2folder($lei, $folders) };
+ $lei->qerr("# no folders match $folder (non-fatal)") if $@;
for my $f (@$folders) {
$ent->{$f} = $lms->location_stats($f); # may be undef
}
diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm
index 8f8e83bc..ccb1823d 100644
--- a/lib/PublicInbox/LeiLcat.pm
+++ b/lib/PublicInbox/LeiLcat.pm
@@ -15,9 +15,8 @@ sub lcat_folder ($$$) {
my ($lei, $lms, $folder) = @_;
$lms //= $lei->lms or return;
my $folders = [ $folder];
- my $err = $lms->arg2folder($lei, $folders);
- $lei->qerr(@{$err->{qerr}}) if $err && $err->{qerr};
- if ($err && $err->{fail}) {
+ eval { $lms->arg2folder($lei, $folders) };
+ if ($@) {
$lei->child_error(0, "# unknown folder: $folder");
} else {
for my $f (@$folders) {
diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm
index 3e725d30..f83c7de2 100644
--- a/lib/PublicInbox/LeiMailSync.pm
+++ b/lib/PublicInbox/LeiMailSync.pm
@@ -437,7 +437,7 @@ sub arg2folder {
my ($self, $lei, $folders) = @_;
my @all = $self->folders;
my %all = map { $_ => 1 } @all;
- my ($err, @no);
+ my @no;
for (@$folders) {
next if $all{$_}; # ok
if (m!\A(maildir|mh):(.+)!i) {
@@ -454,7 +454,7 @@ sub arg2folder {
my $res = match_imap_url($self, $orig, \@all);
if (ref $res) {
$_ = $$res;
- push(@{$err->{qerr}}, <<EOM);
+ $lei->qerr(<<EOM);
# using `$res' instead of `$orig'
EOM
} else {
@@ -466,7 +466,7 @@ EOM
my $res = match_nntp_url($self, $orig, \@all);
if (ref $res) {
$_ = $$res;
- push(@{$err->{qerr}}, <<EOM);
+ $lei->qerr(<<EOM);
# using `$res' instead of `$orig'
EOM
} else {
@@ -479,12 +479,11 @@ EOM
}
if (@no) {
my $no = join("\n\t", @no);
- $err->{fail} = <<EOF;
+ die <<EOF;
No sync information for: $no
Run `lei ls-mail-sync' to display valid choices
EOF
}
- $err;
}
sub forget_folders {
@@ -549,12 +548,8 @@ sub imap_oidhex {
my $mailbox_uri = $uid_uri->clone;
$mailbox_uri->uid(undef);
my $folders = [ $$mailbox_uri ];
- if (my $err = $self->arg2folder($lei, $folders)) {
- if ($err->{fail}) {
- $lei->qerr("# no sync information for $mailbox_uri");
- }
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- }
+ eval { $self->arg2folder($lei, $folders) };
+ $lei->qerr("# no sync information for $mailbox_uri") if $@;
map { unpack('H*',$_) } num_oidbin($self, $folders->[0], $uid_uri->uid)
}
diff --git a/lib/PublicInbox/LeiNoteEvent.pm b/lib/PublicInbox/LeiNoteEvent.pm
index a0591a09..43d5ed0f 100644
--- a/lib/PublicInbox/LeiNoteEvent.pm
+++ b/lib/PublicInbox/LeiNoteEvent.pm
@@ -68,8 +68,9 @@ sub lei_note_event {
return flush_lei($lei) if $folder eq 'done'; # special case
my $lms = $lei->lms or return;
$lms->lms_write_prepare if $new_cur eq ''; # for ->clear_src below
- my $err = $lms->arg2folder($lei, [ $folder ]);
- return if $err->{fail};
+ $lei->{opt}->{quiet} = 1;
+ eval { $lms->arg2folder($lei, [ $folder ]) };
+ return if $@;
my $state = $cfg->get_1("watch.$folder", 'state') // 'tag-rw';
return if $state eq 'pause';
return $lms->clear_src($folder, \$bn) if $new_cur eq '';
diff --git a/lib/PublicInbox/LeiRefreshMailSync.pm b/lib/PublicInbox/LeiRefreshMailSync.pm
index 92673492..51e89b23 100644
--- a/lib/PublicInbox/LeiRefreshMailSync.pm
+++ b/lib/PublicInbox/LeiRefreshMailSync.pm
@@ -74,9 +74,7 @@ EOM
if (defined(my $all = $lei->{opt}->{all})) {
$lms->group2folders($lei, $all, \@folders) or return;
} else {
- my $err = $lms->arg2folder($lei, \@folders);
- $lei->qerr(@{$err->{qerr}}) if $err->{qerr};
- return $lei->fail($err->{fail}) if $err->{fail};
+ $lms->arg2folder($lei, \@folders); # may die
}
$lms->lms_pause; # must be done before fork
$sto->write_prepare($lei);
next prev parent reply other threads:[~2021-09-21 7:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-21 7:41 [PATCH 00/12] lei: fix various annoyances Eric Wong
2021-09-21 7:41 ` [PATCH 01/12] lei inspect: convert to WQ worker Eric Wong
2021-09-21 7:41 ` [PATCH 02/12] lei inspect: support NNTP URLs Eric Wong
2021-09-21 7:41 ` [PATCH 03/12] lei_mail_sync: account for non-unique cases Eric Wong
2021-09-21 7:41 ` Eric Wong [this message]
2021-09-21 7:41 ` [PATCH 05/12] lei lcat: use single queue for ordering Eric Wong
2021-09-21 7:41 ` [PATCH 06/12] doc: lei-security: section for WIP auth methods Eric Wong
2021-09-21 7:41 ` [PATCH 07/12] lei lcat: support NNTP URLs Eric Wong
2021-09-21 7:41 ` [PATCH 08/12] lei: various completion improvements Eric Wong
2021-09-21 7:41 ` [PATCH 09/12] lei q: show progress on >1s preparation phase Eric Wong
2021-09-21 7:41 ` [PATCH 10/12] search: drop reopen retry message Eric Wong
2021-09-21 7:41 ` [PATCH 11/12] lei q: update messages to reflect --save default Eric Wong
2021-09-21 7:41 ` [PATCH 12/12] lei q: improve --limit behavior and progress Eric Wong
2021-09-21 9:29 ` [PATCH 0/3] lei: a few more annoyances fixed Eric Wong
2021-09-21 9:29 ` [PATCH 1/3] t/lei-up: use '-q' to silence non-redirected test Eric Wong
2021-09-21 9:29 ` [PATCH 2/3] script/lei: handle SIGTSTP and SIGCONT Eric Wong
2021-09-21 9:29 ` [PATCH 3/3] lei: umask(077) before opening errors.log 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=20210921074159.20052-5-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).