]> Sergey Matveev's repositories - public-inbox.git/commitdiff
treewide: replace confess with croak
authorEric Wong <e@80x24.org>
Sat, 6 Feb 2021 12:18:38 +0000 (12:18 +0000)
committerEric Wong <e@80x24.org>
Sun, 7 Feb 2021 03:34:32 +0000 (03:34 +0000)
The PublicInbox::Eml (and previously Email::MIME) use of confess
was the primary (or only) culprit behind the lei2mail segfaults
fixed by commit 0795b0906cc81f40.
("ds: guard against stack-not-refcounted quirk of Perl 5").

We never care about a backtrace when dealing with Eml objects
anyways, so it was just a worthless waste of CPU cycles.

We can also drop confess in a few other places.  Since we only
use Perl and Inline::C, users will never be without source
and can replace s/croak/Carp::confess/ on a per-callsite basis
to help report problems.

It's also possible to use PERL5OPT=-MCarp=verbose in the
environment though still potentially risky.

Link: https://public-inbox.org/meta/20210201082833.3293-1-e@80x24.org/
lib/PublicInbox/DS.pm
lib/PublicInbox/Eml.pm
lib/PublicInbox/IPC.pm
lib/PublicInbox/OverIdx.pm

index 263c34580afdb4a4d73316e6a37c6353acbb8352..ec965abe89d4916da8aab84d6e72cb376d969ce1 100644 (file)
@@ -32,7 +32,7 @@ use Scalar::Util qw(blessed);
 use PublicInbox::Syscall qw(:epoll);
 use PublicInbox::Tmpfile;
 use Errno qw(EAGAIN EINVAL);
-use Carp qw(confess carp);
+use Carp qw(carp);
 our @EXPORT_OK = qw(now msg_more dwaitpid);
 
 my $nextq; # queue for next_tick
@@ -335,9 +335,9 @@ retry:
             $ev &= ~EPOLLEXCLUSIVE;
             goto retry;
         }
-        die "couldn't add epoll watch for $fd: $!\n";
+        die "EPOLL_CTL_ADD $self/$sock/$fd: $!";
     }
-    confess("DescriptorMap{$fd} defined ($DescriptorMap{$fd})")
+    croak("FD:$fd in use by $DescriptorMap{$fd} (for $self/$sock)")
         if defined($DescriptorMap{$fd});
 
     $DescriptorMap{$fd} = $self;
@@ -368,7 +368,7 @@ sub close {
     # notifications about it
     my $fd = fileno($sock);
     epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0) and
-        confess("EPOLL_CTL_DEL: $!");
+        croak("EPOLL_CTL_DEL($self/$sock): $!");
 
     # we explicitly don't delete from DescriptorMap here until we
     # actually close the socket, as we might be in the middle of
@@ -587,7 +587,7 @@ sub msg_more ($$) {
 sub epwait ($$) {
     my ($sock, $ev) = @_;
     epoll_ctl($Epoll, EPOLL_CTL_MOD, fileno($sock), $ev) and
-        confess("EPOLL_CTL_MOD $!");
+        croak("EPOLL_CTL_MOD($sock): $!");
 }
 
 # return true if complete, false if incomplete (or failure)
index f7f62e7b26c36be34b26493acc2afad49d6bb470..81a6632b7720c711c75562eb3a1bb99b2a98b01d 100644 (file)
@@ -332,7 +332,7 @@ sub body_set {
 sub body_str_set {
        my ($self, $body_str) = @_;
        my $charset = ct($self)->{attributes}->{charset} or
-               Carp::confess('body_str was given, but no charset is defined');
+               croak('body_str was given, but no charset is defined');
        body_set($self, \(encode($charset, $body_str, Encode::FB_CROAK)));
 }
 
@@ -454,7 +454,7 @@ sub body_str {
                if ($STR_TYPE{$ct->{type}} && $STR_SUBTYPE{$ct->{subtype}}) {
                        return body($self);
                }
-               Carp::confess("can't get body as a string for ",
+               croak("can't get body as a string for ",
                        join("\n\t", header_raw($self, 'Content-Type')));
        }
        decode($charset, body($self), Encode::FB_CROAK);
index a0e6bfee238466ce83839c4e445c71b1219e55ea..0dee2a9241150a01b4af5f53fe2d73553d0796c3 100644 (file)
@@ -11,7 +11,7 @@ package PublicInbox::IPC;
 use strict;
 use v5.10.1;
 use parent qw(Exporter);
-use Carp qw(confess croak);
+use Carp qw(croak);
 use PublicInbox::DS qw(dwaitpid);
 use PublicInbox::Spawn;
 use PublicInbox::OnDestroy;
index 985c5473e7c7cf491386de5fdf07164de982db54..9013ae23e5349486a9913bc8593cc4ade791bed2 100644 (file)
@@ -456,7 +456,7 @@ sub dbh_close {
 sub create {
        my ($self) = @_;
        my $fn = $self->{filename} // do {
-               Carp::confess('BUG: no {filename}') unless $self->{dbh};
+               croak('BUG: no {filename}') unless $self->{dbh};
                return;
        };
        unless (-r $fn) {