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: [PATCH] daemon: rely on $SIG{__WARN__} for error output
Date: Wed, 10 Aug 2022 15:58:01 +0000	[thread overview]
Message-ID: <20220810155801.3329683-1-e@80x24.org> (raw)

warn/carp usage is unavoidable given Perl itself and standard
libraries, so just rely on localized $SIG{__WARN__} from
60d262483a4d6ddf (daemon: use per-listener SIG{__WARN__} callbacks, 2022-08-08)
for all error reporting.

While we're in the area, make some of the error handling more
consistent between IMAP/NNTP/POP3.
---
 lib/PublicInbox/DS.pm        |  4 ++--
 lib/PublicInbox/DSdeflate.pm |  2 +-
 lib/PublicInbox/IMAP.pm      | 12 +++---------
 lib/PublicInbox/NNTP.pm      | 10 ++--------
 lib/PublicInbox/POP3.pm      |  9 ++-------
 5 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 5e8a6a66..26840662 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -660,8 +660,8 @@ sub long_step {
 	if ($@ || !$self->{sock}) { # something bad happened...
 		delete $self->{long_cb};
 		my $elapsed = now() - $t0;
-		$@ and $self->err("%s during long response[$fd] - %0.6f",
-				    $@, $elapsed);
+		$@ and warn("$@ during long response[$fd] - ",
+				sprintf('%0.6f', $elapsed),"\n");
 		$self->out(" deferred[$fd] aborted - %0.6f", $elapsed);
 		$self->close;
 	} elsif ($more) { # $self->{wbuf}:
diff --git a/lib/PublicInbox/DSdeflate.pm b/lib/PublicInbox/DSdeflate.pm
index 639690e2..539adf0f 100644
--- a/lib/PublicInbox/DSdeflate.pm
+++ b/lib/PublicInbox/DSdeflate.pm
@@ -46,7 +46,7 @@ sub enable {
 	my ($class, $self) = @_;
 	my ($in, $err) = Compress::Raw::Zlib::Inflate->new(%IN_OPT);
 	if ($err != Z_OK) {
-		$self->err("Inflate->new failed: $err");
+		warn("Inflate->new failed: $err\n");
 		return;
 	}
 	bless $self, $class;
diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm
index 2be1b763..0a65d87c 100644
--- a/lib/PublicInbox/IMAP.pm
+++ b/lib/PublicInbox/IMAP.pm
@@ -1165,17 +1165,11 @@ sub process_line ($$) {
 	my $err = $@;
 	if ($err && $self->{sock}) {
 		$l =~ s/\r?\n//s;
-		err($self, 'error from: %s (%s)', $l, $err);
+		warn("error from: $l ($err)\n");
 		$tag //= '*';
-		$res = "$tag BAD program fault - command not performed\r\n";
+		$res = \"$tag BAD program fault - command not performed\r\n";
 	}
-	return 0 unless defined $res;
-	$self->write($res);
-}
-
-sub err ($$;@) {
-	my ($self, $fmt, @args) = @_;
-	printf { $self->{imapd}->{err} } $fmt."\n", @args;
+	defined($res) ? $self->write($res) : 0;
 }
 
 sub out ($$;@) {
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index ef01f448..ceaf05f6 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -72,9 +72,8 @@ sub process_line ($$) {
 	my $res = eval { $req->($self, @args) };
 	my $err = $@;
 	if ($err && $self->{sock}) {
-		local $/ = "\n";
-		chomp($l);
-		err($self, 'error from: %s (%s)', $l, $err);
+		$l =~ s/\r?\n//s;
+		warn("error from: $l ($err)\n");
 		$res = \"503 program fault - command not performed\r\n";
 	}
 	defined($res) ? $self->write($res) : 0;
@@ -945,11 +944,6 @@ sub cmd_xpath ($$) {
 	'223 '.join(' ', sort(@paths))."\r\n";
 }
 
-sub err ($$;@) {
-	my ($self, $fmt, @args) = @_;
-	printf { $self->{nntpd}->{err} } $fmt."\n", @args;
-}
-
 sub out ($$;@) {
 	my ($self, $fmt, @args) = @_;
 	printf { $self->{nntpd}->{out} } $fmt."\n", @args;
diff --git a/lib/PublicInbox/POP3.pm b/lib/PublicInbox/POP3.pm
index c993e558..82df257c 100644
--- a/lib/PublicInbox/POP3.pm
+++ b/lib/PublicInbox/POP3.pm
@@ -45,11 +45,6 @@ use constant {
 
 # XXX FIXME: duplicated stuff from NNTP.pm and IMAP.pm
 
-sub err ($$;@) {
-	my ($self, $fmt, @args) = @_;
-	printf { $self->{pop3d}->{err} } $fmt."\n", @args;
-}
-
 sub out ($$;@) {
 	my ($self, $fmt, @args) = @_;
 	printf { $self->{pop3d}->{out} } $fmt."\n", @args;
@@ -364,8 +359,8 @@ sub process_line ($$) {
 		\"-ERR command not recognized\r\n";
 	my $err = $@;
 	if ($err && $self->{sock}) {
-		chomp($l);
-		err($self, 'error from: %s (%s)', $l, $err);
+		$l =~ s/\r?\n//s;
+		warn("error from: $l ($err)\n");
 		$res = \"-ERR program fault - command not performed\r\n";
 	}
 	defined($res) ? $self->write($res) : 0;

                 reply	other threads:[~2022-08-10 15:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220810155801.3329683-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).