]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: rely on $SIG{__WARN__} for error output
authorEric Wong <e@80x24.org>
Wed, 10 Aug 2022 15:58:01 +0000 (15:58 +0000)
committerEric Wong <e@80x24.org>
Wed, 10 Aug 2022 20:11:10 +0000 (20:11 +0000)
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
lib/PublicInbox/DSdeflate.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/POP3.pm

index 5e8a6a6601c51238a859f429bda5f584cda7a1b1..268406628788931b56d71f31e5a8203c2ce963db 100644 (file)
@@ -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}:
index 639690e27f61873cf29234487bac58315b2a51d1..539adf0fbfd47f1097b6ae89952534835cac7006 100644 (file)
@@ -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;
index 2be1b763f30a89f12e84a8c1fa0339026cf3937d..0a65d87cb009f790fe114ce175a0bff639943f18 100644 (file)
@@ -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 ($$;@) {
index ef01f44886203abdeaa3b07dad35226a9e7d6770..ceaf05f6948da0948fa90fb14fd9eae634faf356 100644 (file)
@@ -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;
index c993e558db09c2fbd8de5a15f342099fe6fc4ccd..82df257c2d7002d910ef3d35753512672cacac32 100644 (file)
@@ -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;