From: Eric Wong Date: Wed, 26 Mar 2025 03:35:01 +0000 (+0000) Subject: treewide: use git_quote for diagnostic dumps X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=281c56db2e9493174f633abf5597db68268575d9;p=thirdparty%2Fpublic-inbox.git treewide: use git_quote for diagnostic dumps 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. --- diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index ab6c1e60b..65e3b0ff6 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -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(<{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); diff --git a/lib/PublicInbox/LeiSelfSocket.pm b/lib/PublicInbox/LeiSelfSocket.pm index 0e15bc7c0..e725592a8 100644 --- a/lib/PublicInbox/LeiSelfSocket.pm +++ b/lib/PublicInbox/LeiSelfSocket.pm @@ -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... } diff --git a/lib/PublicInbox/MboxReader.pm b/lib/PublicInbox/MboxReader.pm index 3d78ca231..331ed63dc 100644 --- a/lib/PublicInbox/MboxReader.pm +++ b/lib/PublicInbox/MboxReader.pm @@ -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; } } diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm index b95022b36..d63f63a34 100644 --- a/lib/PublicInbox/NetReader.pm +++ b/lib/PublicInbox/NetReader.pm @@ -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 < 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 < 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;