]> Sergey Matveev's repositories - public-inbox.git/commitdiff
index: warn with info about the message as context
authorEric Wong <e@80x24.org>
Fri, 19 Apr 2019 07:41:22 +0000 (07:41 +0000)
committerEric Wong <e@80x24.org>
Mon, 6 May 2019 19:12:15 +0000 (19:12 +0000)
This can help users track down the source of warnings
when presented with imperfect emails.

While we're at it, make the __WARN__ callback in t/v2writable.t
a no-op since we don't check for warnings, there.

lib/PublicInbox/SearchIdxPart.pm
lib/PublicInbox/V2Writable.pm
script/public-inbox-index
t/v2writable.t

index 7fe2120a425488eb0c076aeb35825dd681101081..51d81a0a21560ef73cac1776f5176f8a29df16e0 100644 (file)
@@ -48,8 +48,15 @@ sub spawn_worker {
 sub partition_worker_loop ($$$$) {
        my ($self, $r, $part, $bnote) = @_;
        $0 = "pi-v2-partition[$part]";
+       my $current_info = '';
+       my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+       local $SIG{__WARN__} = sub {
+               chomp $current_info;
+               $warn_cb->("[$part] $current_info: ", @_);
+       };
        $self->begin_txn_lazy;
        while (my $line = $r->getline) {
+               $current_info = $line;
                if ($line eq "commit\n") {
                        $self->commit_txn_lazy;
                } elsif ($line eq "close\n") {
index 6829a34376105fcd00c1402d0e2a3dbfad7e0b6b..87e8f3eb581a97076b5fd22ea5af917bb623306e 100644 (file)
@@ -72,6 +72,7 @@ sub new {
                im => undef, #  PublicInbox::Import
                parallel => 1,
                transact_bytes => 0,
+               current_info => '',
                xpfx => $xpfx,
                over => PublicInbox::OverIdx->new("$xpfx/over.sqlite3", 1),
                lock_path => "$dir/inbox.lock",
@@ -949,8 +950,10 @@ sub index_sync {
                my $fh = $self->{reindex_pipe} = $git->popen(@cmd, $range);
                my $cmt;
                while (<$fh>) {
+                       chomp;
+                       $self->{current_info} = "$i.git $_";
                        if (/\A$x40$/o && !defined($cmt)) {
-                               chomp($cmt = $_);
+                               $cmt = $_;
                        } elsif (/\A:\d{6} 100644 $x40 ($x40) [AM]\tm$/o) {
                                $self->reindex_oid($mm_tmp, $D, $git, $1,
                                                $regen, $reindex);
index 5adb6e741eff8f2578a780bd40738cd7c42ee7a6..2f810a564f01367a592c0862705074e077a193c9 100755 (executable)
@@ -85,6 +85,9 @@ sub index_dir {
                                }
                        }
                }
+               local $SIG{__WARN__} = sub {
+                       print STDERR $v2w->{current_info}, ': ', @_;
+               };
                $v2w->index_sync({ reindex => $reindex, prune => $prune });
        } else {
                my $s = PublicInbox::SearchIdx->new($repo, 1);
index f171417513440fb578382a1471ba3e13544af26c..2826513b0d66057669408f65df02cf5657944df5 100644 (file)
@@ -253,10 +253,9 @@ EOF
 }
 
 {
-       my @warn;
        my $x = 'x'x250;
        my $y = 'y'x250;
-       local $SIG{__WARN__} = sub { push @warn, @_ };
+       local $SIG{__WARN__} = sub {};
        $mime->header_set('Subject', 'long mid');
        $mime->header_set('Message-ID', "<$x>");
        ok($im->add($mime), 'add excessively long Message-ID');