user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [RFC] index: warn with info about the message as context
Date: Fri, 19 Apr 2019 08:28:26 +0000	[thread overview]
Message-ID: <20190419082826.3183-1-e@80x24.org> (raw)

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 | 7 +++++++
 lib/PublicInbox/V2Writable.pm    | 5 ++++-
 script/public-inbox-index        | 3 +++
 t/v2writable.t                   | 3 +--
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/SearchIdxPart.pm b/lib/PublicInbox/SearchIdxPart.pm
index 7fe2120..51d81a0 100644
--- a/lib/PublicInbox/SearchIdxPart.pm
+++ b/lib/PublicInbox/SearchIdxPart.pm
@@ -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") {
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 6829a34..87e8f3e 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -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);
diff --git a/script/public-inbox-index b/script/public-inbox-index
index 5adb6e7..2f810a5 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -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);
diff --git a/t/v2writable.t b/t/v2writable.t
index f171417..2826513 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -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');
-- 
EW


             reply	other threads:[~2019-04-19  8:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-19  8:28 Eric Wong [this message]
2019-05-06 19:14 ` [pushed] index: warn with info about the message as context Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190419082826.3183-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).