[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/04: cmd/lintian: Simplify handling of uncaught exceptions



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit 79b22057224bf6143a00ac20484ecbd731cd6947
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Oct 1 13:01:21 2017 +0000

    cmd/lintian: Simplify handling of uncaught exceptions
---
 commands/lintian.pm | 51 ++++++++++++++++-----------------------------------
 debian/changelog    |  3 +++
 2 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/commands/lintian.pm b/commands/lintian.pm
index c25c37e..1a1b461 100755
--- a/commands/lintian.pm
+++ b/commands/lintian.pm
@@ -558,7 +558,22 @@ my %opthash = (
     'exp-output:s' => \$experimental_output_opts,
 );
 
-main();
+# dplint has a similar wrapper; but it uses a different exit code
+# for uncaught exceptions (compared to what lintian documents).
+sub _main {
+    eval {
+        _main();
+    };
+    # Cocerce the error to a string
+    if (my $err = "$@") {
+        $err =~ s/\n//;
+        print STDERR "$err\n";
+        print STDERR "Uncaught exception\n";
+        exit(2);
+    }
+    print STDERR "Assertion error: _main returned !?\n";
+    exit(2);
+}
 
 sub main {
     my ($pool);
@@ -1720,40 +1735,6 @@ sub END {
     $SIG{'INT'} = 'DEFAULT';
     $SIG{'QUIT'} = 'DEFAULT';
 
-    # We have to ensure that our exit code is 0, 1 or 2.  Quote from
-    # "perldoc -f die":
-    #
-    # """
-    # If an uncaught exception results in interpreter exit, the exit
-    # code is determined from the values of $! and $? with this
-    # pseudocode:
-    #
-    #   exit $! if $!; # errno
-    #   exit $? >> 8 if $? >> 8; # child exit status
-    #   exit 255;
-    # """
-    #
-    # So, here in the END handler, we abuse the fact that we can alter
-    # the exit code by changing $?.  It is not a perfect solution
-    # (e.g.  if $! is 1, then we might still exit 1 instead of 2), but
-    # it is definitely better than exiting with undocumented exit codes.
-    if ($? != 0 && $? != 2) {
-        # If $? is not 1, then we definitely want $? to be 2.  If
-        # $exit_code != 1, then either we got an uncaught exception
-        # before the first policy violation or we already saw an
-        # internal error that we caught.  Either way, we want to
-        # exit with 2 in this case.
-        #
-        # Sadly, this is unreliable if we saw a policy violation and
-        # then cause an uncaught internal error (where e.g. $! is 1).
-        # In this case we will still exit 1 instead of 2 as we should.
-        # Nevertheless, this is probably a lot more reliable than
-        # Lintian <= 2.5.12 was.
-        if ($? != 1 || $exit_code != 1) {
-            $? = 2;
-        }
-    }
-
     if (1) {
         # Prevent LAB->close, $unpacker->kill_jobs etc. from affecting
         # the exit code.
diff --git a/debian/changelog b/debian/changelog
index 56cd3e2..ce9bb4c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -11,6 +11,9 @@ lintian (2.5.55) UNRELEASED; urgency=medium
     + [CL] Add missing example-script-uses-deprecated-nodejs-location tag.
       (Closes: #877142)
 
+  * commands/lintian.pm:
+    + [NT] Simplify handling of uncaught exceptions.
+
   * t/tests/python-new-python2-package/*:
     + [CL] Correct Depends of python2.7 → python3 in Python 3 test
       package.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: