diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-04-16 15:57:58 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-04-16 16:03:23 +0100 |
commit | 6375554363c111fda70b7540c3c56a0e9cf1497b (patch) | |
tree | 46cd93eda94aa5009dc8626949e23658fb8e4962 /morphlib/mountableimage.py | |
parent | e7e90384da00a8197c5e0363a5a4005754a790eb (diff) | |
download | morph-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/mountableimage.py')
-rw-r--r-- | morphlib/mountableimage.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/morphlib/mountableimage.py b/morphlib/mountableimage.py index 3d29a516..f767228a 100644 --- a/morphlib/mountableimage.py +++ b/morphlib/mountableimage.py @@ -15,6 +15,7 @@ import cliapp +import logging import os import tempfile import gzip @@ -45,7 +46,9 @@ class MountableImage(object): # pragma: no cover infh = gzip.open(path, "rb") morphlib.util.copyfileobj(infh, outfh) infh.close() - except: + except BaseException, e: + logging.error('Caught exception: %s' % str(e)) + logging.info('Removing temporary file %s' % self.temp_path) os.unlink(self.temp_path) raise self.app.status(msg=' Mounting image at %(path)s', @@ -62,17 +65,19 @@ class MountableImage(object): # pragma: no cover chatty=True) try: morphlib.fsutils.unmount(self.app.runcmd, mount_point) - except: - pass + except BaseException, e: + logging.info('Ignoring error when unmounting: %s' % str(e)) try: morphlib.fsutils.undo_device_mapping(self.app.runcmd, path) - except: - pass + except BaseException, e: + logging.info( + 'Ignoring error when undoing device mapping: %s' % str(e)) try: os.rmdir(mount_point) os.unlink(path) - except: - pass + except BaseException, e: + logging.info( + 'Ignoring error when removing temporary files: %s' % str(e)) def __enter__(self): return self.setup(self.artifact_path) |