summaryrefslogtreecommitdiff
path: root/morphlib/plugins/branch_and_merge_plugin.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/plugins/branch_and_merge_plugin.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/plugins/branch_and_merge_plugin.py')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index 25f786e0..e39141cc 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -231,7 +231,9 @@ class BranchAndMergePlugin(cliapp.Plugin):
try:
return self.app.runcmd(['git', 'rev-parse', '--verify', ref],
cwd=repodir)[0:40]
- except:
+ except cliapp.AppException, e:
+ logging.info(
+ 'Ignoring error executing git rev-parse: %s' % str(e))
return None
def resolve_reponame(self, reponame):
@@ -558,11 +560,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
'directory as a workspace: %s' %
dirname)
else:
- try:
- os.makedirs(dirname)
- except:
- raise cliapp.AppException('failed to create workspace: %s' %
- dirname)
+ os.makedirs(dirname)
os.mkdir(os.path.join(dirname, '.morph'))
self.app.status(msg='Initialized morph workspace', chatty=True)
@@ -600,7 +598,9 @@ class BranchAndMergePlugin(cliapp.Plugin):
original_ref], cwd=repo_dir)
return branch_dir
- except:
+ except BaseException, e:
+ logging.error('Caught exception: %s' % str(e))
+ logging.info('Removing half-finished branch %s' % branch_name)
self.remove_branch_dir_safe(workspace, branch_name)
raise
@@ -1513,7 +1513,9 @@ class BranchAndMergePlugin(cliapp.Plugin):
"case, and then repeat the 'morph merge' operation." %
from_branch)
self.app.status(msg="Merge successful")
- except:
+ except BaseException, e:
+ logging.error('Caught exception: %s' % str(e))
+ logging.info('Resetting half-finished merge')
for repo_dir, sha1 in merged_repos.itervalues():
self.reset_work_tree_safe(repo_dir)
raise