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 7A9A01FB07 for ; Tue, 21 Sep 2021 07:41:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/12] lei: simplify internal arg2folder usage Date: Tue, 21 Sep 2021 07:41:51 +0000 Message-Id: <20210921074159.20052-5-e@80x24.org> In-Reply-To: <20210921074159.20052-1-e@80x24.org> References: <20210921074159.20052-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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}}, <qerr(<{qerr}}, <qerr(<{fail} = <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);