summaryrefslogtreecommitdiff
path: root/morphlib/extractedtarball.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-04-16 15:57:58 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-04-16 16:03:23 +0100
commit6375554363c111fda70b7540c3c56a0e9cf1497b (patch)
tree46cd93eda94aa5009dc8626949e23658fb8e4962 /morphlib/extractedtarball.py
parente7e90384da00a8197c5e0363a5a4005754a790eb (diff)
downloadmorph-6375554363c111fda70b7540c3c56a0e9cf1497b.tar.gz
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.
Diffstat (limited to 'morphlib/extractedtarball.py')
-rw-r--r--morphlib/extractedtarball.py11
1 files changed, 8 insertions, 3 deletions
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()