]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei+net_reader: show NNTP message in more failures
authorEric Wong <e@80x24.org>
Wed, 10 Jan 2024 11:18:54 +0000 (11:18 +0000)
committerEric Wong <e@80x24.org>
Thu, 11 Jan 2024 03:00:14 +0000 (03:00 +0000)
Showing absolutely nothing when hitting a server requiring
authentication is a very bad user experience.  While we're
at it, use Net::Cmd->message in more places where we experience
failure, too.

lib/PublicInbox/LeiLsMailSource.pm
lib/PublicInbox/NetReader.pm

index 4b427b268225e44fd9fd73de9fb957352c31acd4..ab6c1e60b17ff52191fe42e9027e8212e077a994 100644 (file)
@@ -42,7 +42,11 @@ sub input_path_url { # overrides LeiInput version
                my $uri = PublicInbox::URInntps->new($url);
                my $nn = $lei->{net}->nn_get($uri) or
                        return $lei->err("E: $uri");
-               my $l = $nn->newsgroups($uri->group); # name => description
+               # $l = name => description
+               my $l = $nn->newsgroups($uri->group) // return $lei->err(<<EOM);
+E: $uri LIST NEWSGROUPS: ${\($lei->{net}->ndump($nn->message))}
+E: login may be required, try adding `-c nntp.debug' to your command
+EOM
                my $sec = $lei->{net}->can('uri_section')->($uri);
                if ($json) {
                        my $all = $nn->list;
index 751043e9cadbe5e3b27928a6b58538dfce9de40b..ec18818bbbd043040f4fa05e1d83049a0c0dedd9 100644 (file)
@@ -14,7 +14,7 @@ our @EXPORT = qw(uri_section imap_uri nntp_uri);
 
 sub ndump {
        require Data::Dumper;
-       Data::Dumper->new(\@_)->Useqq(1)->Terse(1)->Dump;
+       Data::Dumper->new([ $_[-1] ])->Useqq(1)->Terse(1)->Dump;
 }
 
 # returns the git config section name, e.g [imap "imaps://user@example.com"]
@@ -240,19 +240,19 @@ sub nn_new ($$$$) {
                                try_starttls($nn_arg->{Host})) {
                        # soft fail by default
                        $nn->starttls or warn <<"";
-W: <$uri> STARTTLS tried and failed (not requested)
+W: <$uri> STARTTLS tried and failed (not requested): ${\(ndump($nn->message))}
 
                } elsif ($nntp_cfg->{starttls}) {
                        # hard fail if explicitly configured
                        $nn->starttls or die <<"";
-E: <$uri> STARTTLS requested and failed
+E: <$uri> STARTTLS requested and failed: ${\(ndump($nn->message))}
 
                }
        } elsif ($nntp_cfg->{starttls}) {
                $nn->can('starttls') or
                        die "E: <$uri> Net::NNTP too old for STARTTLS\n";
                $nn->starttls or die <<"";
-E: <$uri> STARTTLS requested and failed
+E: <$uri> STARTTLS requested and failed: ${\(ndump($nn->message))}
 
        }
        $nn;
@@ -298,18 +298,21 @@ sub nn_for ($$$$) { # nn = Net::NNTP
                if ($nn->authinfo($u, $p)) {
                        push @{$nntp_cfg->{-postconn}}, [ 'authinfo', $u, $p ];
                } else {
-                       warn "E: <$uri> AUTHINFO $u XXXX failed\n";
+                       warn <<EOM;
+E: <$uri> AUTHINFO $u XXXX: ${\(ndump($nn->message))}
+EOM
                        $nn = undef;
                }
        }
-
-       if ($nntp_cfg->{compress}) {
+       if ($nn && $nntp_cfg->{compress}) {
                # https://rt.cpan.org/Ticket/Display.html?id=129967
                if ($nn->can('compress')) {
                        if ($nn->compress) {
                                push @{$nntp_cfg->{-postconn}}, [ 'compress' ];
                        } else {
-                               warn "W: <$uri> COMPRESS failed\n";
+                               warn <<EOM;
+W: <$uri> COMPRESS: ${\(ndump($nn->message))}
+EOM
                        }
                } else {
                        delete $nntp_cfg->{compress};