]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: use git_quote for diagnostic dumps
authorEric Wong <e@80x24.org>
Wed, 26 Mar 2025 03:35:01 +0000 (03:35 +0000)
committerEric Wong <e@80x24.org>
Thu, 27 Mar 2025 08:52:42 +0000 (08:52 +0000)
git_quote output is probably less alien to most users than
the Perl-specific Data::Dumper, so use it for any messages
which hit stdout/stderr or syslog.

lib/PublicInbox/LeiLsMailSource.pm
lib/PublicInbox/LeiSelfSocket.pm
lib/PublicInbox/MboxReader.pm
lib/PublicInbox/NetReader.pm

index ab6c1e60b17ff52191fe42e9027e8212e077a994..65e3b0ff60c34bfad3bc186787e7a6bdbee67b6a 100644 (file)
@@ -8,6 +8,7 @@ package PublicInbox::LeiLsMailSource;
 use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
+use PublicInbox::Git qw(git_quote);
 
 sub input_path_url { # overrides LeiInput version
        my ($self, $url) = @_;
@@ -44,7 +45,7 @@ sub input_path_url { # overrides LeiInput version
                        return $lei->err("E: $uri");
                # $l = name => description
                my $l = $nn->newsgroups($uri->group) // return $lei->err(<<EOM);
-E: $uri LIST NEWSGROUPS: ${\($lei->{net}->ndump($nn->message))}
+E: $uri LIST NEWSGROUPS: ${\(git_quote($nn->message))}
 E: login may be required, try adding `-c nntp.debug' to your command
 EOM
                my $sec = $lei->{net}->can('uri_section')->($uri);
index 0e15bc7c0798401f297f4e91d4c001358d3488ab..e725592a872ab0822f6e664b35ce96fe7c36801a 100644 (file)
@@ -7,8 +7,7 @@
 package PublicInbox::LeiSelfSocket;
 use v5.12;
 use parent qw(PublicInbox::DS);
-use Data::Dumper;
-$Data::Dumper::Useqq = 1; # should've been the Perl default :P
+use PublicInbox::Git qw(git_quote);
 use PublicInbox::Syscall qw(EPOLLIN);
 use PublicInbox::IPC;
 
@@ -30,7 +29,7 @@ sub event_step {
                for (@fds) { open my $fh, '+<&=', $_ };
        }
        return $self->close if $buf eq '';
-       warn Dumper({ 'unexpected self msg' => $buf, fds => \@fds });
+       warn 'W: unexpected self msg: ', git_quote($buf), " fds=(@fds)\n";
        # TODO: figure out what to do with these messages...
 }
 
index 3d78ca23118a248e7df6425d0303bb693572fcdd..331ed63dcf32ce632d797db3c8cab605fb26b61b 100644 (file)
@@ -5,8 +5,7 @@
 package PublicInbox::MboxReader;
 use strict;
 use v5.10.1; # check regexps before v5.12
-use Data::Dumper;
-$Data::Dumper::Useqq = 1; # should've been the default, for bad data
+use PublicInbox::Git qw(git_quote);
 
 my $from_strict =
        qr/^From \S+ +\S+ \S+ +\S+ [^\n:]+:[^\n:]+:[^\n:]+ [^\n:]+\n/sm;
@@ -94,18 +93,18 @@ sub _mbox_cl ($$$;@) {
                }
                while (my $hdr = _extract_hdr(\$buf)) {
                        PublicInbox::Eml::strip_from($$hdr) or
-                               die "E: no 'From ' line in:\n", Dumper($hdr);
+                               die "E: no 'From ' line in:\n", git_quote($hdr);
                        my $eml = PublicInbox::Eml->new($hdr);
                        next unless $eml->raw_size;
                        my @cl = $eml->header_raw('Content-Length');
                        my $n = scalar(@cl);
                        $n == 0 and die "E: Content-Length missing in:\n",
-                                       Dumper($eml->as_string);
+                                       git_quote($eml->as_string);
                        $n == 1 or die "E: multiple ($n) Content-Length in:\n",
-                                       Dumper($eml->as_string);
+                                       git_quote($eml->as_string);
                        $cl[0] =~ /\A[0-9]+\z/ or die
                                "E: Content-Length `$cl[0]' invalid\n",
-                                       Dumper($eml->as_string);
+                                       git_quote($eml->as_string);
                        if (($eml->{bdy} = _cl_body($mbfh, \$buf, $cl[0]))) {
                                $uxs_from and
                                        ${$eml->{bdy}} =~ s/^>From /From /sgm;
@@ -115,7 +114,7 @@ sub _mbox_cl ($$$;@) {
                if ($r == 0) {
                        $buf =~ /[^ \r\n\t]/ and
                                warn "W: leftover at end of mboxcl/mboxcl2:\n",
-                                       Dumper(\$buf);
+                                       git_quote(\$buf);
                        return;
                }
        }
index b95022b36853cbc01c0f410039a3ffd92ea163cf..d63f63a34d36cc3c32106adb8e644c72f75e6c1d 100644 (file)
@@ -8,16 +8,12 @@ use parent qw(Exporter PublicInbox::IPC);
 use PublicInbox::Eml;
 use PublicInbox::Config;
 use PublicInbox::DS;
+use PublicInbox::Git qw(git_quote);
 our %IMAPflags2kw = map {; "\\\u$_" => $_ } qw(seen answered flagged draft);
 $IMAPflags2kw{'$Forwarded'} = 'forwarded';  # RFC 5550
 
 our @EXPORT = qw(uri_section imap_uri nntp_uri);
 
-sub ndump {
-       require Data::Dumper;
-       Data::Dumper->new([ $_[-1] ])->Useqq(1)->Terse(1)->Dump;
-}
-
 # returns the git config section name, e.g [imap "imaps://user@example.com"]
 # without the mailbox, so we can share connections between different inboxes
 sub uri_section ($) {
@@ -243,19 +239,20 @@ sub nn_new ($$$$) {
                                try_starttls($nn_arg->{Host})) {
                        # soft fail by default
                        $nn->starttls or warn <<"";
-W: <$uri> STARTTLS tried and failed (not requested): ${\(ndump($nn->message))}
+W: <$uri> STARTTLS tried and failed (not requested): ${\(
+git_quote($nn->message))}
 
                } elsif ($nntp_cfg->{starttls}) {
                        # hard fail if explicitly configured
                        $nn->starttls or die <<"";
-E: <$uri> STARTTLS requested and failed: ${\(ndump($nn->message))}
+E: <$uri> STARTTLS requested and failed: ${\(git_quote($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: ${\(ndump($nn->message))}
+E: <$uri> STARTTLS requested and failed: ${\(git_quote($nn->message))}
 
        }
        $nn;
@@ -302,7 +299,7 @@ sub nn_for ($$$$) { # nn = Net::NNTP
                        push @{$nntp_cfg->{-postconn}}, [ 'authinfo', $u, $p ];
                } else {
                        warn <<EOM;
-E: <$uri> AUTHINFO $u XXXX: ${\(ndump($nn->message))}
+E: <$uri> AUTHINFO $u XXXX: ${\(git_quote($nn->message))}
 EOM
                        $nn = undef;
                }
@@ -314,7 +311,7 @@ EOM
                                push @{$nntp_cfg->{-postconn}}, [ 'compress' ];
                        } else {
                                warn <<EOM;
-W: <$uri> COMPRESS: ${\(ndump($nn->message))}
+W: <$uri> COMPRESS: ${\(git_quote($nn->message))}
 EOM
                        }
                } else {
@@ -809,7 +806,7 @@ sub _nntp_fetch_all ($$$) {
        my $restore = PublicInbox::DS::allow_sigs qw(INT QUIT TERM);
        my ($nr, $beg, $end) = $nn->group($group);
        unless (defined($nr)) {
-               my $msg = ndump($nn->message);
+               my $msg = git_quote($nn->message);
                return "E: GROUP $group <$sec> $msg";
        }
        undef $restore;
@@ -848,7 +845,7 @@ sub _nntp_fetch_all ($$$) {
                $restore = PublicInbox::DS::allow_sigs qw(INT QUIT TERM);
                my $raw = $nn->article($art);
                unless (defined($raw)) {
-                       my $msg = ndump($nn->message);
+                       my $msg = git_quote($nn->message);
                        if ($nn->code == 421) { # pseudo response from Net::Cmd
                                $err = "E: $msg";
                                last;