From 6375554363c111fda70b7540c3c56a0e9cf1497b Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 16 Apr 2013 15:57:58 +0100 Subject: Stop using bare except: statements It is almost never a good idea to catch all exceptions, and then do nothing about them. This patch logs all caught exceptions so that the user has some possibilty to debug what is happening. Also, make ./check check for bare excepts and fail the test suite if it finds anything. --- morphlib/extractedtarball.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'morphlib/extractedtarball.py') diff --git a/morphlib/extractedtarball.py b/morphlib/extractedtarball.py index e435b1ef..fd98cd92 100644 --- a/morphlib/extractedtarball.py +++ b/morphlib/extractedtarball.py @@ -16,6 +16,7 @@ import cliapp import gzip +import logging import os import tempfile import shutil @@ -41,7 +42,9 @@ class ExtractedTarball(object): # pragma: no cover self.tempdir = tempfile.mkdtemp(dir=self.app.settings['tempdir']) try: morphlib.bins.unpack_binary(self.tarball, self.tempdir) - except: + except BaseException, e: + logging.error('Caught exception: %s' % str(e)) + logging.debug('Removing temporary directory %s' % self.tempdir) shutil.rmtree(self.tempdir) raise return self.tempdir @@ -51,8 +54,10 @@ class ExtractedTarball(object): # pragma: no cover tarball=os.path.basename(self.tarball), chatty=True) try: shutil.rmtree(self.tempdir) - except: - pass + except BaseException, e: + logging.warning( + 'Error when removing temporary directory %s: %s' % + (self.tempdir, str(e))) def __enter__(self): return self.setup() -- cgit v1.2.1