summaryrefslogtreecommitdiff
path: root/morphlib/builder2.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/builder2.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/builder2.py')
-rw-r--r--morphlib/builder2.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 7ded281e..93af25e7 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -304,7 +304,9 @@ class ChunkBuilder(BuilderBase):
log_name = log.real_filename
self.run_commands(builddir, destdir, log)
self.create_devices(destdir)
- except:
+ except BaseException, e:
+ logging.error('Caught exception: %s' % str(e))
+ logging.info('Cleaning up staging area')
self.staging_area.chroot_close()
if log_name:
with open(log_name) as f:
@@ -760,8 +762,11 @@ class DiskImageBuilder(SystemKindBuilder): # pragma: no cover
shutil.copyfileobj(ifh, ofh, 1024 * 1024)
ofh.close()
- except:
+ except BaseException, e:
+ logging.error('Caught exception: %s' % str(e))
+ logging.info('Removing unfinished disk image %s' % image_name)
os.remove(image_name)
+ logging.info('Removing unfinished file from cache')
handle.abort()
raise