]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei ls-mail-source: gracefully handle network failures
authorEric Wong <e@80x24.org>
Thu, 9 Nov 2023 10:09:39 +0000 (10:09 +0000)
committerEric Wong <e@80x24.org>
Thu, 9 Nov 2023 21:53:50 +0000 (21:53 +0000)
All network connections may fail, so try to emit a helpful
error message instead of attempting to dispatch methods off
`undef'.

lib/PublicInbox/LeiLsMailSource.pm

index 50799270a8de20959381544e3d01495cb5fd3707..4b427b268225e44fd9fd73de9fb957352c31acd4 100644 (file)
@@ -19,7 +19,8 @@ sub input_path_url { # overrides LeiInput version
        if ($url =~ m!\Aimaps?://!i) {
                my $uri = PublicInbox::URIimap->new($url);
                my $sec = $lei->{net}->can('uri_section')->($uri);
-               my $mic = $lei->{net}->mic_get($uri);
+               my $mic = $lei->{net}->mic_get($uri) or
+                       return $lei->err("E: $uri");
                my $l = $mic->folders_hash($uri->path); # server-side filter
                @$l = map { $_->[2] } # undo Schwartzian transform below:
                        sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] }
@@ -39,7 +40,8 @@ sub input_path_url { # overrides LeiInput version
                }
        } elsif ($url =~ m!\A(?:nntps?|s?news)://!i) {
                my $uri = PublicInbox::URInntps->new($url);
-               my $nn = $lei->{net}->nn_get($uri);
+               my $nn = $lei->{net}->nn_get($uri) or
+                       return $lei->err("E: $uri");
                my $l = $nn->newsgroups($uri->group); # name => description
                my $sec = $lei->{net}->can('uri_section')->($uri);
                if ($json) {